Vize

computed-with-control

Computed value whose dependencies are declared explicitly.

Package @vizejs/composable/computed-with-control
Own the source vize lib pull composable:computed-with-control
Runtime exports computedWithControl
Gzip budget 1024 B

Usage

import { computedWithControl } from "@vizejs/composable/computed-with-control";

Runtime contract

Utility Category Stability SSR Hydration Cleanup Targets Host globals Uses
computedWithControl reactivity experimental safe stable reactive-scope web, server, worker, native, desktop, terminal — —

API

computedWithControl

Computed value whose dependencies are declared explicitly. Only changes of source (or a manual ComputedWithControl.trigger) invalidate the cache; reactive reads inside getter do not. Useful when the getter reads non-reactive data or should ignore some reactive reads. The getter receives the previous value and runs lazily on the next read. Pure derived state: SSR-safe; the invalidation watcher follows the owning reactive scope.

function computedWithControl<Value>( source: ComputedWithControlSource, getter: (previous: Value | undefined) => Value, options: ComputedWithControlOptions = {}, ): ComputedWithControl<Value>
const snapshot = computedWithControl(version, () => expensiveRead(store));
snapshot.trigger(); // force a refresh

Types

ComputedWithControl

Readonly cached value plus a manual invalidation trigger.

Member Type Description
trigger () => void Mark the cached value stale; the next read recomputes it.

ComputedWithControlOptions

Options for computedWithControl.

Member Type Description
deep? boolean Invalidate on nested changes of the explicit sources.