Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/connect/wrapMapToProps.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
41 changes: 39 additions & 2 deletions test/components/connect.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Passthrough {...this.props} />
}
}

TestUtils.renderIntoDocument(
<ProviderMock store={store}>
<div>
<Container name="a" />
</div>
</ProviderMock>
)

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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -2169,6 +2206,6 @@ describe('React', () => {

store.dispatch({ type: 'INC' })
})

})
})