Patch
One DOM edit, as the differ emits it and the client applies it.
A patch names its target by a path of childNodes indices from the page's mount anchor, which is design/live.md's Option A: the tree the server diffs is canonical (Canonical), so tree child index equals DOM child index and the two sides count the same list. The anchor's children hold the component's root element at index 0, so every path into the component starts with 0. Payloads carry Html rather than rendered strings, so the reference applier in this module's tests can apply them structurally; Wire renders at the boundary, once.
expect is the integrity check (design/live.md §1.1, fail loud): the node name the patch believes sits at its path, "#text" for a text node. The client refuses a patch whose target disagrees, records it, and never applies it — the check exists to catch the exact bug this design historically breeds, both sides counting children differently. SetText carries none because its op admits only one node kind, which the applier checks by node type; the two Option[String] cases are None only at the anchor, which is found by page id, not by walking, so a walk of zero steps has nothing to verify.
Application order is part of the contract. The applier applies a frame's patches in list order, and the differ guarantees each patch's path is valid at its turn: within one positional child list it emits in-place updates first (counts unchanged), then removals from the highest index down (so earlier indices stay true), then a single append. Within one keyed child list the order is: removals (highest index first), then moves (each from/to read against the list as the previous move left it), then inserts at ascending final positions, then content patches addressed at final positions — structural before content, so every content path is true by the time it applies. DiffSuite pins both orders.
Attributes
- Source
- Patch.scala
- Graph
-
- Supertypes