deepDiffObject()function

deepDiffObject(left: ImmutableObject, right: R): R | DeepPartial<R> | typeof SAME
ParamType
leftImmutableObject
The old object. required
rightR
The new/target object. required
Return
R | DeepPartial<R> | typeof SAME
Object containing the missing/updated properties that left needs to become right.
- If the two values are deeply equal the SAME constant is returned.
- If left isn't an object then the result can't be diffed so entire right is returned.

Diff two objects to produce the transformation needed to transform left into right

  • Only works on enumerable own keys (as returned by Object.keys()).
  • Includes a constructor check — if left and right have different constructors they will not be merged and right will be returned (ensures arrays aren't compared with objects).
  • Properties that exist in left but not right (i.e. have been deleted) are represented with undefined

Examples

deepDiffObject({ a: 1 }, { a: 1 }) // SAME
deepDiffObject({ a: 1, b: 2 }, { a: 1 }) // { b: undefined }