Define a read-only signal computed from the values of other signals.
Dependencies are tracked automatically: whatever signals fn reads during
evaluation become its dependencies, re-tracked on every evaluation (so
conditional reads narrow or widen them dynamically).
Evaluation is lazy and memoized: fn does not run until the computed is
first read, and re-runs only when a read (or an effect/subscription)
finds a dependency actually changed. A re-evaluation that produces an
equal value (strict equality) stops propagation — dependents do not
re-evaluate.
fn must be pure and synchronous: writing to a signal during a computed
evaluation throws a TypeError. Computed signals cannot be written to;
calling one with an argument throws a TypeError.
Define a read-only signal computed from the values of other signals. Dependencies are tracked automatically: whatever signals
fnreads during evaluation become its dependencies, re-tracked on every evaluation (so conditional reads narrow or widen them dynamically).Evaluation is lazy and memoized:
fndoes not run until the computed is first read, and re-runs only when a read (or an effect/subscription) finds a dependency actually changed. A re-evaluation that produces an equal value (strict equality) stops propagation — dependents do not re-evaluate.fnmust be pure and synchronous: writing to a signal during a computed evaluation throws a TypeError. Computed signals cannot be written to; calling one with an argument throws a TypeError.