const source = { b: { c: 99 }, d: undefined }; // d: undefined will delete
const dest = proxy({ a: 1, b: { x: 5 }, d: 4 });
merge(dest, source);
merge(dest, 'b', { y: 6 }); // merge into dest.b
merge(dest, 'c', { z: 7 }); // merge.c doesn't exist yet, so it will just be assigned
console.log(dest); // proxy({ a: 1, b: { c: 99, x: 5, y: 6 }, c: { z: 7 } })
Like copy, but uses merge semantics. Properties in dst
not present in src
are kept.
null
/undefined
in src
delete properties in dst
.
When the destination is an object and the source is an array, its keys are used as (sparse) array indices.
const source = { b: { c: 99 }, d: undefined }; // d: undefined will delete
const dest = proxy({ a: 1, b: { x: 5 }, d: 4 });
merge(dest, source);
merge(dest, 'b', { y: 6 }); // merge into dest.b
merge(dest, 'c', { z: 7 }); // merge.c doesn't exist yet, so it will just be assigned
console.log(dest); // proxy({ a: 1, b: { c: 99, x: 5, y: 6 }, c: { z: 7 } })
Like copy, but uses merge semantics. Properties in
dst
not present insrc
are kept.null
/undefined
insrc
delete properties indst
.When the destination is an object and the source is an array, its keys are used as (sparse) array indices.