diff --git a/src/core/plugins/view/root-injects.js b/src/core/plugins/view/root-injects.js index 568ac6ac..fc67f165 100644 --- a/src/core/plugins/view/root-injects.js +++ b/src/core/plugins/view/root-injects.js @@ -20,9 +20,12 @@ const RootWrapper = (reduxStore, ComponentToWrap) => class extends Component { } const makeContainer = (getSystem, component, reduxStore) => { - const mapStateToProps = component.prototype.mapStateToProps || function(state) { - return {state} + const mapStateToProps = function(state, ownProps) { + const propsForContainerComponent = Object.assign({}, ownProps, getSystem()) + const ori = component.prototype.mapStateToProps || (state => state.toJS()) + return ori(state, propsForContainerComponent) } + let wrappedWithSystem = SystemWrapper(getSystem, component, reduxStore) let connected = connect( mapStateToProps )(wrappedWithSystem) if(reduxStore) diff --git a/test/core/system/system.js b/test/core/system/system.js index 9113b2d1..3abd02d9 100644 --- a/test/core/system/system.js +++ b/test/core/system/system.js @@ -518,6 +518,59 @@ describe("bound system", function(){ // Then expect(renderedComponent.text()).toEqual("This came from mapStateToProps and this came from the system and this came from my own props") }) + + it("gives the system and own props as props to a container's `mapStateToProps` function", function() { + // Given + class ContainerComponent extends PureComponent { + mapStateToProps(nextState, props) { + const { exampleSelectors, fromMapState, fromOwnProps } = props + return { + "fromMapState": `This came from mapStateToProps ${exampleSelectors.foo()} ${fromOwnProps}` + } + } + + static defaultProps = { + "fromMapState" : "" + } + + render() { + const { fromMapState } = this.props + return ( +
{ fromMapState }
+ ) + } + } + const system = new System({ + plugins: [ + ViewPlugin, + { + components: { + ContainerComponent + } + }, + { + statePlugins: { + example: { + selectors: { + foo() { return "and this came from the system" } + } + } + } + } + ] + }) + + // When + var Component = system.getSystem().getComponent("ContainerComponent", true) + const renderedComponent = render( + + + + ) + + // Then + expect(renderedComponent.text()).toEqual("This came from mapStateToProps and this came from the system and this came from my own props") + }) }) })