[]previous and next page

SourceNode

Anything that can be read reactively and notify observers: a signal, a memo, or a custom source of a primitive.

Anything that can be read reactively and notify observers: a signal, a memo, or a custom source of a primitive. Exported from @shadow-js/core/extend as SourceNode. Read one with track; after changing it, call markObservers and schedule (or notify).

Import#

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

Signature#

ts
interface Source {
  /**
   * The node kind: 0 for a signal and for any custom source, which have no sources of their own; a
   * computation has its own kind. A refresh walks only the sources whose kind is not 0.
   */
  readonly kind: number;
  /** The current value. */
  value: unknown;
  /**
   * The computations that read this source in their last run, as pairs: an observer, then the index of this source in
   * that observer's `sources`. Null or empty when none. Read it with `observersOf`, which returns the observers alone.
   */
  observers: Edges<Computation> | null;
  /** Stamp of the last computation run that tracked this source (dedupes repeated reads). */
  stamp: number;
}

Members#

Name Type Description
kind readonly kind: number The node kind: 0 for a signal and for any custom source, which have no sources of their own; a computation has its own kind. A refresh walks only the sources whose kind is not 0.
value value: unknown The current value.
observers observers: Edges<Computation> | null The computations that read this source in their last run, as pairs: an observer, then the index of this source in that observer's sources. Null or empty when none. Read it with observersOf, which returns the observers alone.
stamp stamp: number Stamp of the last computation run that tracked this source (dedupes repeated reads).