diff --git a/src/connect/wrapMapToProps.js b/src/connect/wrapMapToProps.js index 93eaa80b3..6b39c7961 100644 --- a/src/connect/wrapMapToProps.js +++ b/src/connect/wrapMapToProps.js @@ -43,10 +43,12 @@ export function wrapMapToPropsFunc(mapToProps, methodName) { : proxy.mapToProps(stateOrDispatch) } - proxy.dependsOnOwnProps = getDependsOnOwnProps(mapToProps) + // allow detectFactoryAndVerify to get ownProps + proxy.dependsOnOwnProps = true proxy.mapToProps = function detectFactoryAndVerify(stateOrDispatch, ownProps) { proxy.mapToProps = mapToProps + proxy.dependsOnOwnProps = getDependsOnOwnProps(mapToProps) let props = proxy(stateOrDispatch, ownProps) if (typeof props === 'function') { diff --git a/test/components/connect.spec.js b/test/components/connect.spec.js index b8c777b19..fa11213bd 100644 --- a/test/components/connect.spec.js +++ b/test/components/connect.spec.js @@ -1881,6 +1881,43 @@ describe('React', () => { expect(memoizedReturnCount).toBe(2) }) + it('should allow a mapStateToProps factory consuming just state to return a function that gets ownProps', () => { + const store = createStore(() => ({ value: 1 })) + + let initialState + let initialOwnProps + let secondaryOwnProps + const mapStateFactory = function (factoryInitialState) { + initialState = factoryInitialState + initialOwnProps = arguments[1]; + return (state, props) => { + secondaryOwnProps = props + return { } + } + } + + @connect(mapStateFactory) + class Container extends Component { + render() { + return + } + } + + TestUtils.renderIntoDocument( + +
+ +
+
+ ) + + store.dispatch({ type: 'test' }) + expect(initialOwnProps).toBe(undefined) + expect(initialState).toNotBe(undefined) + expect(secondaryOwnProps).toNotBe(undefined) + expect(secondaryOwnProps.name).toBe("a") + }) + it('should allow providing a factory function to mapDispatchToProps', () => { let updatedCount = 0 let memoizedReturnCount = 0 @@ -2134,7 +2171,7 @@ describe('React', () => { class BlockUpdates extends Component { shouldComponentUpdate() { return false; } render() { return this.props.children; } - } + } const mapStateToProps = expect.createSpy().andCall(state => ({ count: state })) @connect(mapStateToProps) @@ -2169,6 +2206,6 @@ describe('React', () => { store.dispatch({ type: 'INC' }) }) - + }) })