The type of the objects being copied.
The destination object/array (proxied or unproxied).
The source object/array (proxied or unproxied). It won't be modified.
Bitmask controlling copy behavior:
dst
not present in src
are kept.
null
/undefined
in src
delete properties in dst
. Handles partial array updates via object keys.dst
yet, a reference to the array/object in src
will be made, instead of creating a copy. If the array/object already exists, it won't be replaced (by a reference), but all items will be individually checked and copied like normal, keeping changes (and therefore UI updates) to a minimum.Error if attempting to copy an array into a non-array or vice versa (unless MERGE is set, allowing for sparse array updates).
const source = proxy({ a: 1, b: { c: 2 } });
const dest = proxy({ b: { d: 3 } });
copy(dest, source);
console.log(dest); // proxy({ a: 1, b: { c: 2 } })
const source = { b: { c: 99 }, d: undefined }; // d: undefined will delete
const dest = proxy({ a: 1, b: { x: 5 }, d: 4 });
copy(dest, source, MERGE);
console.log(dest); // proxy({ a: 1, b: { c: 99, x: 5 } })
Recursively copies properties or array items from
src
todst
. It's designed to work efficiently with reactive proxies created by proxy.dst
with the same constructor as the corresponding object insrc
,copy
will recursively copy properties into the existingdst
object instead of replacing it. This minimizes change notifications for reactive updates.dst
andsrc
.