State
Reactive.State takes the type, then the initial value. Reactive.Any keeps the state
loosely typed. The const on the left is the name of the state.
Reactive.Function("Counter", () => {
const count = Reactive.State(Maths.Integer)(0);
Layout.Row(() => {
Content.Text(count);
});
});The slot
The first run stores the initial value in the slot of this call. A later run finds that slot and keeps the stored value. The slot comes from the position of the call in the program. A set runs the program again from the start. The call sits in a function. A module can hold a state as well.
Reading and writing
A state is readable and writable. A read uses the name. Reactive.Set stores a new value on
that state. Setting a reverse runs its block, and Reactive.Set
carries that write out to state.
const next = Maths.Add(count, 1);
Reactive.Set(count, next);A field of a state is ordinary data. The field read is a calculation. The field has no writable half. Changing a field means building a new value and setting the whole state. The lock is on the whole value. A field has no lock of its own.
Arguments and return
A caller may pass a state to an input, an output, or a binding. An input reads it. An output writes it. A binding reads it and writes it.
A function may return a state. Only the forward value comes out. That result is not writable. A function writes through an output or a reverse argument.
Locks
The stored value carries one read lock. Setting the state clears that read lock. The write lock is a counter. The counter means a reverse process is using the value. The program does not look at a lock. A driver does.