createSignalNode
// ---------- reactive cells ---------- /** Creates the storage of a signal: its value, its equality and the observers that read it.
// ---------- reactive cells ----------
/**
Creates the storage of a signal: its value, its equality and the observers that read it. Read it
with readSignal and write it with writeSignal; useSignal is built this way.
Import#
ts
import { createSignalNode } from "@shadow-js/core/extend";
Signature#
ts
function createSignalNode<T>(value: T, equals: Equals<T>, name?: string): Signal<T>
Parameters#
| Name | Description |
|---|---|
value |
Initial value. |
equals |
Decides whether a write is a change: readers are notified only when it returns false. false notifies on every write. |
name |
Label shown by devtools. Undefined leaves the signal unnamed. |
Returns#
The signal node. It has no owner: it lives as long as something references it.
Examples#
ts
import { createSignalNode, readSignal, writeSignal } from "@shadow-js/core/extend";
const temperature = createSignalNode<number>(20, Object.is, "temperature");
const read = () => readSignal(temperature);
writeSignal(temperature, 21);
console.log(read()); // 21