Signal API
Reference for writable reactive state.
This page lists the supported API for the Signal module.
Signal
Signal stores writable reactive state. Read it with Signal.get when you want dependency tracking, or Signal.peek when you want a snapshot.
Signal.t
1type t<'a>
A signal value containing state of type 'a.
Signal.make
1let make: (2 'a,3 ~name: option<string>=?,4 ~equals: option<('a, 'a) => bool>=?,5) => Signal.t<'a>
Create a signal with an initial value. ~name is for debugging, and ~equals replaces the default JavaScript strict equality check.
Signal.get
1let get: Signal.t<'a> => 'a
Read the current value and subscribe the active computed or effect, if one exists.
Signal.peek
1let peek: Signal.t<'a> => 'a
Read the current value without creating a dependency.
Signal.set
1let set: (Signal.t<'a>, 'a) => unit
Replace the signal value. Dependents are notified only when the equality check says the value changed.
Signal.update
1let update: (Signal.t<'a>, 'a => 'a) => unit
Compute the next value from the current value.
Signal.batch
1let batch: (unit => 'a) => 'a
Run several writes as one scheduler flush. The callback result is returned.
Signal.untrack
1let untrack: (unit => 'a) => 'a
Run a block without dependency capture.
Example
1open Xote23let count = Signal.make(0)45let increment = () => {6 Signal.update(count, n => n + 1)7}89let current = Signal.peek(count)