mergeObject()function
mergeObject(left: L, right: R, recursor?: MergeRecursor): L & R
| Param | Type | |
|---|---|---|
left | L | The left object to merge into. required |
right | R | The right object whose props replace or merge with left. required |
recursor | MergeRecursor | Function that merges each property of the object. - Defaults to exactMerge() to just swap the property for a newer one if it exists.- Use deepMerge() as the recursor to merge objects deeply. |
| Return | |
|---|---|
L & R | Merged object. - Returned instances will be the same if no changes were made. - Will be left instance if no properties changed.- Will be a new merged object otherwise. |
Merge two data objects.
Properties that exist in right will replace or be deeply merged with properties in left.
- Only works on enumerable own keys (as returned by
Object.keys()). - Always returns a new object (or the
leftobject if no changes were made). - Resulting object is
cleaned, i.e. properties inleftorrightthat areundefinedwill be removed from the merged object.
Examples
mergeObject({ a: 1 }, { b: 2 }) // { a: 1, b: 2 }