patch
@rotorsoft/act-root / act-patch/src / patch
Function: patch()
patch<
S>(original,patches):Readonly<S>
Defined in: libs/act-patch/src/patch.ts:25
Immutably deep-merges patches into original.
This is a pure function — it never mutates its arguments and always returns a deterministic result for the same inputs.
Merging rules:
- Plain objects: Deep merge recursively
- Arrays, Dates, RegExp, Maps, Sets, TypedArrays: Replace entirely
undefinedornullvalues: Delete the property- Primitives: Replace with patch value
Structural sharing:
Unpatched subtrees are reused by reference, not deep-copied. This is safe
because Act state is always Readonly<S> and events are immutable — state
is only ever updated through new patches. This is the same approach used by
Immer, Redux Toolkit, and other immutable state libraries.
Type Parameters
S
S extends Schema
Parameters
original
Readonly<S>
The original state object to patch (not mutated)
patches
Readonly<Patch<S>> | null | undefined
The patches to apply (recursive partial of the state shape)
Returns
Readonly<S>
A new state object with patches applied, sharing unpatched subtree references