[]previous and next page

observersOf

The computations that read a signal or memo in their last run, in the order their edges were made.

The computations that read a signal or memo in their last run, in the order their edges were made. It is a snapshot, so changing the returned array changes no edge. The node's own observers array stores pairs (the observer and an index for the engine), so read it through this function.

Import#

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

Signature#

ts
function observersOf(source: Source): Computation[]

Parameters#

Name Description
source A signal, a memo or a custom source.

Returns#

The memos and effects that read it now.

Examples#

ts
import { createComputation, createSignalNode, flushSync, observersOf, readSignal } from "@shadow-js/core/extend";

const count = createSignalNode<number>(1, Object.is, "count");
createComputation({ kind: "effect", fn: () => void readSignal(count) });
flushSync();
console.log(observersOf(count).length); // 1