Created
July 6, 2017 09:05
-
-
Save ernestofreyreg/46d6b03347f15b0c94cc8d955e375544 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, {Component} from 'react' | |
const connect = (component, actionCreator, initialState) => { | |
const attach = instance => ({ | |
set: fn => new Promise(resolve => instance.setState(fn, resolve)), | |
get: () => instance.state | |
}) | |
return class Connected extends Component { | |
constructor(props, context) { | |
super(props, context) | |
this.state = initialState | |
this.actions = actionCreator(attach(this)) | |
} | |
render () { | |
return React.createElement(component, {...this.props,...this.actions, ...this.state}) | |
} | |
} | |
} | |
export default connect |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment