ComputationOptions
// ---------- computations (memos and effects) ---------- /** Options of createComputation.
// ---------- computations (memos and effects) ----------
/** Options of createComputation.
Import#
ts
import type { ComputationOptions } from "@shadow-js/core/extend";
Signature#
ts
interface ComputationOptions {
/**
* `"memo"` creates a cached value that readers pull with {@link readComputation}; `"effect"`
* creates a side effect that the scheduler runs.
*/
kind: "memo" | "effect";
/**
* The computation. It is tracked: every source it reads becomes a dependency. It receives the
* previous value (a memo's last value, or an effect's last computed value when `apply` is set;
* `undefined` otherwise). A memo stores its result; an effect without `apply` may return a
* cleanup function.
*/
fn: (previous: never) => unknown;
/**
* Memos: decides whether a recomputation changed the value; readers are notified only when it
* returns `false`, and `false` always propagates. Ignored for effects.
* @default Object.is
*/
equals?: Equals<unknown>;
/**
* Label shown by devtools and diagnostics.
* @default undefined (the node is unnamed)
*/
name?: string;
/**
* Effects: run in the render phase, synchronously at creation and before user effects in each
* flush. Ignored for memos.
* @default false
*/
render?: boolean;
/**
* Effects with `apply`: skip the first call of `apply`; `fn` still runs and tracks.
* @default false
*/
defer?: boolean;
/**
* Memos: do not compute until the first read.
* @default false (the memo computes once at creation)
*/
lazy?: boolean;
/**
* Memos that run component setup (such as a hot-reload wrapper): writing signals inside is
* legitimate there, so the dev-mode write guard stays off.
* @default false
*/
allowWrites?: boolean;
/**
* Effects: second stage, run untracked with the value `fn` computed and the previous one. It may
* return a cleanup function.
* @default undefined (`fn` is the whole effect)
*/
apply?: (value: never, previous: never) => unknown;
/**
* Owner to attach to. `null` creates a node that no owner disposes.
* @default the current owner
*/
owner?: Owner | null;
/**
* Effects: always run in the transition lane (the watcher behind `useDeferredValue`).
* @default false
*/
lane?: boolean;
}
Members#
| Name | Type | Description |
|---|---|---|
kind |
kind: "memo" | "effect" |
"memo" creates a cached value that readers pull with readComputation; "effect" creates a side effect that the scheduler runs. |
fn |
fn: (previous: never) => unknown |
The computation. It is tracked: every source it reads becomes a dependency. It receives the previous value (a memo's last value, or an effect's last computed value when apply is set; undefined otherwise). A memo stores its result; an effect without apply may return a cleanup function. |
equals? |
equals?: Equals<unknown> |
Memos: decides whether a recomputation changed the value; readers are notified only when it returns false, and false always propagates. Ignored for effects. |
name? |
name?: string |
Label shown by devtools and diagnostics. |
render? |
render?: boolean |
Effects: run in the render phase, synchronously at creation and before user effects in each flush. Ignored for memos. |
defer? |
defer?: boolean |
Effects with apply: skip the first call of apply; fn still runs and tracks. |
lazy? |
lazy?: boolean |
Memos: do not compute until the first read. |
allowWrites? |
allowWrites?: boolean |
Memos that run component setup (such as a hot-reload wrapper): writing signals inside is legitimate there, so the dev-mode write guard stays off. |
apply? |
apply?: (value: never, previous: never) => unknown |
Effects: second stage, run untracked with the value fn computed and the previous one. It may return a cleanup function. |
owner? |
owner?: Owner | null |
Owner to attach to. null creates a node that no owner disposes. |
lane? |
lane?: boolean |
Effects: always run in the transition lane (the watcher behind useDeferredValue). |