Last active
January 31, 2018 06:28
-
-
Save jyliang/164823ff7361259ad4b6010a7703bbc8 to your computer and use it in GitHub Desktop.
react native inspect component
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const _ = require('lodash') | |
/** | |
* Deep diff between two object, using lodash | |
* @param {Object} object Object compared | |
* @param {Object} base Object to compare with | |
* @return {Object} Return a new object who represent the diff | |
*/ | |
function difference(object, base) { | |
function changes(object, base) { | |
return _.transform(object, function (result, value, key) { | |
if (!_.isEqual(value, base[key])) { | |
result[key] = (_.isObject(value) && _.isObject(base[key])) ? changes(value, base[key]) : value; | |
} | |
}); | |
} | |
return changes(object, base); | |
} | |
shouldComponentUpdate(nextProps, nextState) { | |
// if (__DEV__) { | |
// let stateChanges = difference(nextState, this.state) | |
// let propChanges = difference(nextProps, this.props) | |
// let stateIgnoreList = ["currentHomeFeedOffset"] | |
// let stateKeys = _.filter(Object.keys(stateChanges), function(o) {return !stateIgnoreList.includes(o)}) | |
// let propKeys = Object.keys(propChanges) | |
// let shouldIgnoreUpdate = stateKeys.length + propKeys.length === 0 | |
// let shouldUpdate = (nextProps ? nextProps.isFocused : this.props.isFocused) && !shouldIgnoreUpdate | |
// if (shouldUpdate) { | |
// console.log(`change ${JSON.stringify(stateChanges)} + ${JSON.stringify(propChanges)}`) | |
// } | |
// return shouldUpdate | |
// } | |
return nextProps.isFocused | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment