Skip to content

Commit

Permalink
Only check equality on final props if custom mergeProps is supplied
Browse files Browse the repository at this point in the history
  • Loading branch information
tgriesser committed Feb 4, 2016
1 parent 43344c9 commit 06de7fd
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/components/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,22 @@ export default function connect(mapStateToProps, mapDispatchToProps, mergeProps,
mapDispatchToProps || defaultMapDispatchToProps

const finalMergeProps = mergeProps || defaultMergeProps
const checkMergedEquals = finalMergeProps !== defaultMergeProps
const { pure = true, withRef = false } = options

// Helps track hot reloading.
const version = nextVersion++

function computeMergedProps(stateProps, dispatchProps, parentProps) {
const mergedProps = finalMergeProps(stateProps, dispatchProps, parentProps)
invariant(
isPlainObject(mergedProps),
'`mergeProps` must return an object. Instead received %s.',
mergedProps
)
return mergedProps
}

return function wrapWithConnect(WrappedComponent) {
class Connect extends Component {
shouldComponentUpdate() {
Expand Down Expand Up @@ -106,16 +117,6 @@ export default function connect(mapStateToProps, mapDispatchToProps, mergeProps,
return isFactory ? this.computeDispatchProps(store, props) : checkStateShape(mappedDispatch, true)
}

computeMergedProps(stateProps, dispatchProps, parentProps) {
const mergedProps = finalMergeProps(stateProps, dispatchProps, parentProps)
invariant(
isPlainObject(mergedProps),
'`mergeProps` must return an object. Instead received %s.',
mergedProps
)
return mergedProps
}

updateStatePropsIfNeeded() {
const nextStateProps = this.computeStateProps(this.store, this.props)
if (this.stateProps && shallowEqual(nextStateProps, this.stateProps)) {
Expand All @@ -137,8 +138,8 @@ export default function connect(mapStateToProps, mapDispatchToProps, mergeProps,
}

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

Expand Down

0 comments on commit 06de7fd

Please sign in to comment.