[]previous and next page

SignalNode

The storage of a signal: its value, its equality and the computations that read it.

The storage of a signal: its value, its equality and the computations that read it. Exported from @shadow-js/core/extend as SignalNode; create one with createSignalNode, read it with readSignal and write it with writeSignal, which notifies its readers. Build a custom primitive on it the way useSignal does.

Import#

ts
import { SignalNode } from "@shadow-js/core/extend";

Signature#

ts
class Signal<T = unknown> implements Source

Members#

Name Type Description
T T = unknown
kind readonly kind: number Always 0, the kind of a signal.
value value: T The current value. Assigning it directly notifies no one: use writeSignal, or call notify after the assignment.
equals equals: Equals<T> Decides whether a write is a change; false treats every write as one.
observers observers: Edges<Computation> | null The computations that read this signal in their last run, as pairs (see Source.observers).
stamp stamp Stamp of the last computation run that tracked this signal (dedupes repeated reads).
name name: string | undefined Label shown by devtools and diagnostics.

Examples#

ts
import { createSignalNode, readSignal, SignalNode, writeSignal } from "@shadow-js/core/extend";

const count = createSignalNode<number>(0, Object.is, "count");
writeSignal(count, 1);
console.log(readSignal(count), count instanceof SignalNode); // 1 true