Skip to content

Instantly share code, notes, and snippets.

@bobmacneal
Last active February 17, 2020 20:04
Show Gist options
  • Save bobmacneal/09a14032eb3d31e58aa9e0d0d88292a0 to your computer and use it in GitHub Desktop.
Save bobmacneal/09a14032eb3d31e58aa9e0d0d88292a0 to your computer and use it in GitHub Desktop.
import isEqual from 'lodash/isEqual'
import isObject from 'lodash/isObject'
import transform from 'lodash/transform'
export const diffBetweenTwoObjects = (object, base) => {
const changes = (object, base) => {
return transform(object, (result, value, key) => {
if (!isEqual(value, base[key])) {
result[key] = (isObject(value) && isObject(base[key])) ? changes(value, base[key]) : value
}
})
}
return changes(object, base)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment