Aberdeen - v1.10.1
    Preparing search index...

    Function copy

    • 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 dst with the same constructor as the corresponding object in src, copy will recursively copy properties into the existing dst object instead of replacing it. This minimizes change notifications for reactive (proxied) destinations.
      • Fast with Proxies: When copying to/from proxied objects, copy uses Aberdeen internals to speed things up (compared to a non-Aberdeen-aware deep copy).

      Type Parameters

      • T extends object

        The type of the objects being copied.

      Parameters

      • dst: T

        The destination object/array/Map (proxied or unproxied).

      • src: T

        The source object/array/Map (proxied or unproxied). It won't be modified.

      Returns boolean

      true if any changes were made to dst, or false if not.

      Error if attempting to copy an array into a non-array or vice versa.

      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 } })
    • 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

      • T extends object

      Parameters

      • dst: T
      • dstKey: keyof T

        Optional key in dst to copy into.

      • src: T[keyof T]

      Returns boolean