diff --git a/src/Root.js b/src/Root.js index 6d3bb6198e..ce1709a4c2 100644 --- a/src/Root.js +++ b/src/Root.js @@ -3,7 +3,8 @@ import createDispatcher from './createDispatcher'; export default class ReduxRoot { static propTypes = { - stores: PropTypes.object.isRequired, + dispatcher: PropTypes.object, + stores: PropTypes.object, children: PropTypes.func.isRequired }; @@ -12,12 +13,19 @@ export default class ReduxRoot { }; constructor(props) { - this.dispatcher = createDispatcher(); - this.dispatcher.receiveStores(props.stores); + this.dispatcher = props.dispatcher || createDispatcher(); + if (props.stores) { + this.dispatcher.receiveStores(props.stores); + } } componentWillReceiveProps(nextProps) { - this.dispatcher.receiveStores(nextProps.stores); + if (nextProps.dispatcher) { + this.dispatcher = nextProps.dispatcher; + } + if (nextProps.stores) { + this.dispatcher.receiveStores(nextProps.stores); + } } getChildContext() { diff --git a/src/addons/root.js b/src/addons/root.js index f7c28d5764..ab830e697d 100644 --- a/src/addons/root.js +++ b/src/addons/root.js @@ -2,13 +2,13 @@ import React from 'react'; import Root from '../Root'; import getDisplayName from './getDisplayName'; -export default function root(stores) { +export default function root(stores, dispatcher = null) { return DecoratedComponent => class ReduxRootDecorator { static displayName = `ReduxRoot(${getDisplayName(DecoratedComponent)})`; render() { return ( - + {props => } );