delta
@rotorsoft/act-root / act-patch/src / delta
Function: delta()
delta<
S>(before,after):Readonly<Patch<S>>
Defined in: libs/act-patch/src/delta.ts:26
Compute the smallest Patch<S> that, when applied to before via patch(),
yields an object semantically equal to after. The semantic inverse of patch().
Round-trip guarantee:
patch(before, delta(before, after)) deeply equals after.
Rules (mirror patch's merging rules):
- Same reference (
Object.is) → omit (mirrors structural sharing) - Both plain objects → recurse (mirrors deep merge)
- Otherwise (any other diff) → set to
after[K](mirrors wholesale replace) - Key in
beforeonly → set tonull(mirrors delete)
Equality is reference-based, matching patch's structural-sharing model.
Two structurally-equal-but-distinct values (e.g. two Date instances with the
same getTime(), or two arrays with the same elements) are treated as
different and emit a replacement — safe for the round-trip identity, just
slightly less compact.
Type Parameters
S
S extends Schema
Parameters
before
Readonly<S>
The original state object
after
Readonly<S>
The desired state object
Returns
Readonly<Patch<S>>
The smallest patch that transforms before into after