Signal
- Type parameters:
T
A mutable value that tracks its readers.
Reading a signal inside an effect or a computed value subscribes that reader, which reruns when the signal is set to a different value. Subscriptions are automatic.
var count = new Signal(0);
var doubled = new Computed(() -> count.value * 2);
Reactive.effect(() -> trace(doubled.value));
count.value = 2; // traces 4Constructor
function new(initial:T, ?equals:(T, T) -> Bool)equals decides whether a new value is a change. The default is ==.
Properties
var value(get, set):TReading returns the value and subscribes the reader. Assigning sets the value.
var get(default, null):() -> TReturns the value and subscribes the running effect or computed value, which reruns when the value changes.
var peek(default, null):() -> TReturns the value without subscribing the reader.
var set(default, null):(next:T) -> VoidSets the value and reruns its dependents, unless the value is unchanged.
var update(default, null):(change:(T) -> T) -> VoidSets the value to the result of change applied to the current value.