@zhelvis/structure-ts
    Preparing search index...

    Function computeDiff

    • Computes the structural difference between two values.

      This function performs a deep comparison of two values and returns an array of actions that describe how to transform the old value into the new value. It handles objects, arrays, and primitive values, and includes protection against circular references.

      Parameters

      • oldValue: unknown

        The original value to compare from

      • newValue: unknown

        The new value to compare to

      • visited: WeakSet<object> = ...

        WeakSet used internally to track visited objects for circular reference detection

      Returns undefined | Diff

      Array of diff actions, or undefined if the values are identical

      // Compare simple objects
      const diff = computeDiff({ a: 1, b: 2 }, { a: 1, b: 3, c: 4 });
      // Returns: [
      // { type: ActionType.CHANGE, path: ['b'], from: 2, to: 3 },
      // { type: ActionType.ADD, path: ['c'], value: 4 }
      // ]

      // Compare arrays
      const arrayDiff = computeDiff([1, 2, 3], [1, 4, 3]);
      // Returns: [{ type: ActionType.CHANGE, path: [1], from: 2, to: 4 }]

      // Identical values return undefined
      const noDiff = computeDiff({ a: 1 }, { a: 1 }); // undefined