Skip to content

Instantly share code, notes, and snippets.

@marcusvmsa
Created February 8, 2018 13:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcusvmsa/6753767f06b7f795ef4128d5d27cd32a to your computer and use it in GitHub Desktop.
Save marcusvmsa/6753767f06b7f795ef4128d5d27cd32a to your computer and use it in GitHub Desktop.
Deep diff between two object, using lodash/fp
// https://gist.github.com/Yimiprod/7ee176597fef230d1451#gistcomment-2324809
const transform = _.transform.convert({
cap: false,
});
const iteratee = baseObj => (result, value, key) => {
if (!_.isEqual(value, baseObj[key])) {
const valIsObj = _.isObject(value) && _.isObject(baseObj[key]);
result[key] = valIsObj === true ? differenceObject(value, baseObj[key]) : value;
}
};
const differenceObject = (targetObj, baseObj) => transform(iteratee(baseObj), null, targetObj);
const dO = differenceObject(this.props, nextProps);
console.log('dO', dO);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment