Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Adds List validation for reduxComponent #8558

Merged
merged 1 commit into from
Apr 28, 2017
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
8 changes: 8 additions & 0 deletions app/common/state/immutableUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ const api = {
return Immutable.List.isList(obj)
},

isSameHashCode: (first, second) => {
if (first === null && second === null) {
return true
}

return second !== null ? first.hashCode() === second.hashCode() : false
},

makeImmutable: (obj) => {
return api.isImmutable(obj) ? obj : Immutable.fromJS(obj)
}
Expand Down
11 changes: 9 additions & 2 deletions app/renderer/components/reduxComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const ImmutableComponent = require('./immutableComponent')
const React = require('react')
const windowStore = require('../../../js/stores/windowStore')
const debounce = require('../../../js/lib/debounce')
const {isList, isSameHashCode} = require('../../common/state/immutableUtil')

const mergePropsImpl = (stateProps, dispatchProps, ownProps) => {
return Object.assign({}, stateProps, dispatchProps, ownProps)
Expand Down Expand Up @@ -44,9 +45,15 @@ class ReduxComponent extends ImmutableComponent {
this.setState(this.buildProps(nextProps))
}

checkParam (old, next, prop) {
return isList(next[prop])
? !isSameHashCode(next[prop], old[prop])
: next[prop] !== old[prop]
}

shouldComponentUpdate (nextProps, nextState) {
return Object.keys(nextState).some((prop) => nextState[prop] !== this.state[prop]) ||
Object.keys(nextProps).some((prop) => nextProps[prop] !== this.props[prop])
return Object.keys(nextState).some((prop) => this.checkParam(this.state, nextState, prop)) ||
Object.keys(nextProps).some((prop) => this.checkParam(this.props, nextProps, prop))
}

mergeProps (stateProps, dispatchProps, ownProps) {
Expand Down