[]previous and next page

refresh

Brings a memo or effect node up to date if one of its sources changed, without tracking it.

Brings a memo or effect node up to date if one of its sources changed, without tracking it. Use it to settle a node before reading its fields directly.

Import#

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

Signature#

ts
function refresh(node: Computation): void

Parameters#

Name Description
node A node from createComputation. A node that is up to date is left as is.

Throws#

  • ShadowError CYCLE_DETECTED when a dependency is still computing (a cycle). An effect that re-runs routes its errors to its owner's error handler.

Examples#

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

const count = createSignalNode<number>(1, Object.is);
const doubled = createComputation({ kind: "memo", fn: () => readSignal(count) * 2 });
writeSignal(count, 2);
refresh(doubled);
console.log(doubled.value); // 4