Aberdeen - v1.1.0
    Preparing search index...

    Function merge

    • 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.

      Type Parameters

      • T extends object

      Parameters

      • dst: T
      • value: Partial<T>

      Returns boolean

      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 } })
      const messages = proxy(['msg1', 'msg2', 'msg3']);
      const update = { 1: 'updated msg2' }; // Update using object key as index
      merge(messages, update);
      console.log(messages); // proxy(['msg1', 'updated msg2', 'msg3'])
    • 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.

      Type Parameters

      • T extends object

      Parameters

      • dst: T
      • dstKey: keyof T
      • value: Partial<T[keyof T]>

      Returns boolean

      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 } })
      const messages = proxy(['msg1', 'msg2', 'msg3']);
      const update = { 1: 'updated msg2' }; // Update using object key as index
      merge(messages, update);
      console.log(messages); // proxy(['msg1', 'updated msg2', 'msg3'])