Reactivity API
Import these APIs from min-reactive-framework.
signal
Section titled “signal”function signal<T>(initial: T): Signal<T>;Signal<T> exposes a writable .value. A read in a tracked context subscribes that context. Assignments equal under Object.is are ignored. NaN compares equal to itself and the two signed zeros compare differently. To observe edits to a stored object or array, assign a new value or use signals for the fields that change independently.
computed
Section titled “computed”function computed<T>(read: () => T): ReadonlySignal<T>;Produces a lazy, cached value from the signals and computed values read during evaluation. A different read path replaces the previous dependency set. An equal result can stop propagation to observers downstream. A thrown error stays cached until dependencies change. Keep the callback pure. Writing a signal while evaluating a computation or a binding expression raises an error.
const useDefault = signal(true);const fallback = signal("Ada");const custom = signal("Mina");const name = computed(() => (useDefault.value ? fallback.value : custom.value));effect
Section titled “effect”type Dispose = () => void;function effect(run: () => void | Dispose): Dispose;Runs when a tracked read changes. Effects registered during a render or a batch run after the pending work is applied. A standalone registration outside a flush or batch runs synchronously. A returned cleanup runs before the next invocation or on disposal. Nested effects belong to the current invocation. Disposing an effect also removes its queued work.
function batch<T>(run: () => T): T;Groups synchronous writes and preserves the callback’s return value. Reads, including reads of derived values, see the current state inside the batch. The outermost batch flushes structural work, bindings and form values, mount callbacks, then effects. If a callback throws, completed writes still take effect. Independent queued work is processed before errors are reported.
untracked
Section titled “untracked”function untracked<T>(read: () => T): T;Evaluates a function without collecting reads for its surrounding context. Use it for incidental reads such as logging or for a read needed to calculate a write that should only follow a different dependency.
Related types
Section titled “Related types”| Type | Role |
|---|---|
Signal<T> |
Mutable signal produced by signal. |
ReadonlySignal<T> |
Read-only signal produced by computed and passed to list row factories. |
ReactiveValue<T> |
A plain T, a read-only signal of T, or a synchronous function returning T. |
Dispose |
Cleanup function with signature () => void. |
See signals and effects for an interactive batch example.