Skip to content

Settle

settle(before, after) makes after consistent again. preview and commit call it, so a feature never fixes arrows itself. It compares the two documents through after.touched, so after must derive from before.

Rules

settle drops a binding when:

  • It dangles. Its arrow is missing or no longer an arrow, or its target is missing or is an arrow.
  • Its arrow was moved away from it. The arrow’s terminal moved in page space, the binding was not written in this change, and its target did not change. Moving an arrow on its own detaches it. Moving it together with its target keeps the binding. Dragging a terminal onto a new target writes a new binding, which is kept. A change that does not move the terminal, such as a new colour or arrowhead, keeps the binding.

Then it re-resolves, with resolveArrow, every arrow that:

  • is bound to a changed shape, or
  • changed itself and still has a binding, or
  • has a binding written in this change.

A resolved arrow that comes out data-equal keeps its old object. Every other record keeps its identity. The resolved arrows are recorded in touched, so diff sees them.

Why one pass is enough

Resolving an arrow changes only that arrow. Binding targets are never arrows, because settle drops any binding whose target is an arrow. So no resolved arrow is the target of another binding, and the pass cannot cause more work. The detach rule reads only what the feature changed, not what settle changed.

Loading

settle(EMPTY_DOC, fromShapeDocument(document)) treats every record as new. Every binding counts as written, so none is detached, and every bound arrow snaps to its targets. load does this.