Created
May 31, 2016 18:39
-
-
Save mrblueblue/d82f3a34620c8566cf3b8c4734ce01f9 to your computer and use it in GitHub Desktop.
This file contains 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 {PropTypes} from 'react' | |
import {compose, getContext, mapProps} from 'recompose' | |
const noop = () => ({}) | |
function connect(mapStateToProps = noop, mapDispatchToProps = noop) { | |
return compose( | |
getContext({ | |
store: PropTypes.shape({ | |
getState: PropTypes.func, | |
dispatch: PropTypes.func, | |
subscribe: PropTypes.func, | |
}) | |
}), | |
mapProps(({store, ...rest}) => Object.assign( | |
{ }, | |
{...rest}, | |
mapStateToProps(store.getState(), {...rest}), | |
mapDispatchToProps(store.dispatch, {...rest}) | |
)) | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment