Skip to content

Commit

Permalink
Fix reduxjs#337, update impure component with custom mergeProps
Browse files Browse the repository at this point in the history
  • Loading branch information
tgriesser committed Apr 6, 2016
1 parent 93cdfae commit a2de685
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/components/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export default function connect(mapStateToProps, mapDispatchToProps, mergeProps,

updateMergedPropsIfNeeded() {
const nextMergedProps = computeMergedProps(this.stateProps, this.dispatchProps, this.props)
if (this.mergedProps && checkMergedEquals && shallowEqual(nextMergedProps, this.mergedProps)) {
if (pure && this.mergedProps && checkMergedEquals && shallowEqual(nextMergedProps, this.mergedProps)) {
return false
}

Expand Down
33 changes: 33 additions & 0 deletions test/components/connect.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1639,5 +1639,38 @@ describe('React', () => {
expect(mapStateCalls).toBe(2)
expect(renderCalls).toBe(1)
})

it('should update impure components with custom mergeProps', () => {
let store = createStore(() => ({}))
let renderCount = 0

@connect(null, null, () => ({ a: 1 }), { pure: false })
class Container extends React.Component {
render() {
++renderCount
return <div />
}
}

class Parent extends React.Component {
componentDidMount() {
this.forceUpdate()
}
render() {
return <Container />
}
}

TestUtils.renderIntoDocument(
<ProviderMock store={store}>
<Parent>
<Container />
</Parent>
</ProviderMock>
)

expect(renderCount).toBe(2)
})

})
})

0 comments on commit a2de685

Please sign in to comment.