Skip to main content

Module diff

Module diff 

Source
Expand description

Scene diff and patch application.

A scene diff is itself a scene value (a scene/patch node), so it can be snapshotted, sent over the wire, or replayed like any other Scene. diff produces a patch that records the minimal set-and-remove operations turning old into new; apply replays a patch onto a scene. The contract is exactness: apply(old, diff(old, new)) reconstructs new exactly.

The diff descends through equal-length sequences and through map keys, so moving or editing one node re-emits only that node. Length-changing sequences and type changes fall back to a whole-value set at that path, which still reconstructs exactly. Maps whose keys are REORDERED (the same keys in a new order) also fall back to a whole-value set: a key-matched descent emits no ops for a pure reorder, yet apply preserves the old key order, so a fallback is required for apply(old, diff(old,new)) == new to hold exactly. Path addressing (the k/i wire form and the navigate/set/remove logic) is the shared sim_value::path primitive.

Functionsยง

apply
Apply patch to scene, returning the reconstructed scene.
diff
Build the patch that turns old into new.