track
Records that the running computation read source, so a later markObservers on it marks that computation stale.
Records that the running computation read source, so a later markObservers on it marks
that computation stale. Call it in the reader of a custom source; readSignal does it for
signals. Does nothing when untracked, and a source read again in the same run is recorded once.
Import#
ts
import { track } from "@shadow-js/core/extend";
Signature#
ts
function track(source: Source): void
Parameters#
| Name | Description |
|---|---|
source |
The source that was read. |
Examples#
ts
import { markObservers, schedule, type SourceNode, track } from "@shadow-js/core/extend";
const clock: SourceNode = { kind: 0, value: Date.now(), observers: null, stamp: 0 };
export function now(): number {
track(clock);
return clock.value as number;
}
setInterval(() => {
clock.value = Date.now();
markObservers(clock);
schedule();
}, 1000);