Documentation / base / applyPatch
Function: applyPatch()
applyPatch(
base,patch):DiffValue
Defined in: libs/base/src/diff.ts:337
Apply a DiffPatch to a given base value to produce a new value.
Behavior:
set: sets/replaces the value at path (deep-cloned).del: deletes the value at path; deleting the root yieldsundefined.arr: applies array elementsets first, thenins, thendel(descending indices), minimizing index-shift side-effects during mutation.
Structural handling:
- Intermediate containers are created as needed: arrays for numeric next keys, objects otherwise.
- If an
arroperation targets a non-array location, the array result is reconstructed by replaying the sub-ops against an empty array and then placed at the path.
Immutability:
- The function starts by deep-cloning
baseto avoid mutating the input.
Parameters
base
The source value onto which the patch is applied.
patch
The patch to apply (produced by diff).
Returns
The result of applying patch to base.