Skip to content

Instantly share code, notes, and snippets.

@hkjpotato
Created July 11, 2017 19:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hkjpotato/d4466c8476218850568d639422f809ee to your computer and use it in GitHub Desktop.
Save hkjpotato/d4466c8476218850568d639422f809ee to your computer and use it in GitHub Desktop.
import React, { PropTypes } from 'react'
const storeShape = PropTypes.shape({
subscribe: PropTypes.func.isRequired,
dispatch: PropTypes.func.isRequired,
getState: PropTypes.func.isRequired
})
const subscriptionShape = PropTypes.shape({
trySubscribe: PropTypes.func.isRequired,
notifyNestedSubs: PropTypes.func.isRequired
})
class Provider extends React.Component {
constructor(props, context) {
super(props, context)
this.store = props.store;
}
getChildContext() {
return { store: this.store, parentSub: null }
}
render() {
return React.Children.only(this.props.children)
}
}
Provider.childContextTypes = {
store: storeShape,
parentSub: subscriptionShape,
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment