copy
Call Signature
Section titled “Call Signature”copy<
T>(dst,src):boolean
Defined in: aberdeen.ts:1832
Recursively copies properties or array items from src to dst.
It’s designed to work efficiently with reactive proxies created by proxy.
- Minimizes Updates: When copying between objects/arrays (proxied or not), if a nested object
exists in
dstwith the same constructor as the corresponding object insrc,copywill recursively copy properties into the existingdstobject instead of replacing it. This minimizes change notifications for reactive (proxied) destinations. - Fast with Proxies: When copying to/from proxied objects,
copyuses Aberdeen internals to speed things up (compared to a non-Aberdeen-aware deep copy).
Type Parameters
Section titled “Type Parameters”T extends object
The type of the objects being copied.
Parameters
Section titled “Parameters”T
The destination object/array/Map (proxied or unproxied).
T
The source object/array/Map (proxied or unproxied). It won’t be modified.
Returns
Section titled “Returns”boolean
true if any changes were made to dst, or false if not.
Throws
Section titled “Throws”Error if attempting to copy an array into a non-array or vice versa.
Example
Section titled “Example”Basic Copy
const $source = A.proxy({ a: 1, b: { c: 2 } });const $dest = A.proxy({ b: { d: 3 } });A.copy($dest, $source);console.log($dest); // proxy({ a: 1, b: { c: 2 } })A.copy($dest, 'b', { e: 4 });console.log($dest); // proxy({ a: 1, b: { e: 4 } })Call Signature
Section titled “Call Signature”copy<
T>(dst,dstKey,src):boolean
Defined in: aberdeen.ts:1839
Like above, but copies src into dst[dstKey]. This is useful if you’re unsure if dst[dstKey]
already exists (as the right type of object) or if you don’t want to subscribe to dst[dstKey].
Type Parameters
Section titled “Type Parameters”T extends object
Parameters
Section titled “Parameters”T
dstKey
Section titled “dstKey”keyof T
Optional key in dst to copy into.
T[keyof T]
Returns
Section titled “Returns”boolean