The complete object to merge into.
The partial object containing updates. All properties are optional except those specified by idKeys.
OptionalidKeys: readonly K[]The keys used as identifiers for merging array items. Can be a single key or an array of keys. When multiple keys are provided, an object is expected to have only one of these keys.
A new object that is the result of merging partial into full.
If trying to merge an identified array into a non-array property.
Merging behavior:
full with non-undefined values from partial.idKey, it merges items with matching IDs.
b. If array items don't have the idKey, it replaces the entire array.partial that don't exist in full.// Merging simple objects
const full = { a: 1, b: 2 };
const partial = { b: -1 };
deepMergeOn(full, partial, 'id'); // Returns { a: 1, b: -1 }
// Merging nested objects with arrays
const full = {
a: 1,
b: 2,
children: [
{ id: '1', x: 10 },
{ id: '2', y: 20 }
]
};
const partial = {
b: 3,
children: [
{ id: '2', y: 30 }
]
};
deepMergeOn(full, partial, 'id');
// Returns:
// {
// a: 1,
// b: 3,
// children: [
// { id: '1', x: 10 },
// { id: '2', y: 30 }
// ]
// }
// Merging arrays without identifier keys
const full = { data: [1, 2, 3] };
const partial = { data: [4, 5] };
deepMergeOn(full, partial, 'id'); // Returns { data: [4, 5] }
// Adding new properties
const full = { a: 1 };
const partial = { b: 2 };
deepMergeOn(full, partial, 'id'); // Returns { a: 1, b: 2 }
Deeply merges a partial object into a full object, using specified identifier keys for array merging.
This function performs a deep merge with special handling for arrays containing objects with identifier keys. It's particularly useful for merging complex nested structures where some properties should be merged rather than replaced.