settle

fun settle(declared: V, read: () -> V, write: (V) -> Unit, onSettled: (V) -> Unit = {})

Settles the widget on declared: writes it through write unless read already answers with it. The value the widget ends up holding becomes the baseline later changes are measured against, and the one declared has now been answered for, so a widget that answered with a value of its own is not written again on every later pass.

A widget can settle on a different value than declared - an index outside its items, a number off the grid it snaps to. When it does, onSettled is handed what the widget was left holding, once the widget has been left alone, so what it reports is final.

Parameters

declared

the value this pass declares for the property.

read

answers with the value the widget holds. Called once before the write, and a second time only where a write was made.

write

puts a value onto the widget, marked as this wrapper's own so the events it raises are not taken for the user's.

onSettled

handed what the widget was left holding, where that differs from declared. Defaults to doing nothing.


fun <R> settle(block: MirrorState.SettlementScope<V>.() -> R): R

Runs block as a settlement of this mirror's own: the value the widget is left holding when it returns is one this pass asked for and read back itself, so it is recorded as an answer rather than as news.

settle settles a declaration by writing it. A write the widget answers by dropping part of what it held settles through this instead, wrapped around both the write and the read that records what survived it. block must close the settlement, and throws where it does not - see SettlementScope for the two ways to close one.

What decides whether a read-back belongs inside is whether this pass still owes the widget anything, and what settles that is whether the pass put the declaration back before it read. A pass that re-applied the declaration and read what the widget was left holding owes nothing further, whatever the widget kept of it: that is an answer. A pass that changed the widget by writing some other property, leaving a standing declaration lying where the widget dropped it, does still owe it: that is news, and its observed stays outside, where the change it records is what brings the pass that puts the declaration back.

Return

whatever block returned, once the settlement has closed.

Parameters

block

makes the write and closes the settlement on its SettlementScope receiver. A change it makes to this mirror's property needs no pass of its own.