Function: computed

index.computed

computed<T>(getter, name?): ReadonlySignal<T>

Creates a lazily-evaluated, memoized reactive computed signal derived from reactive sources.

Type parameters

Name Description
T The return type of the computation.

Parameters

Name Type Description
getter () => T Pure function that computes the derived value from reactive dependencies.
name? string Optional diagnostic name for debugging, telemetry, and observability tracking.

Returns

ReadonlySignal<T>

A ReadonlySignal exposing the derived, cached .value.

Remarks

The computed primitive takes a pure evaluation function and automatically tracks any reactive signals, domain stores, collections, or other computed signals accessed during its calculation. It caches its output value until one of its tracked dependencies mutates, at which point it marks itself as dirty and invalidates downstream subscribers. The getter is only re-executed on demand when its .value is read.

Dependency tracking is dynamic: dependencies not read in the latest evaluation branch are cleaned up automatically.

Example

import { signal, computed } from '@banksia/signals';

const firstName = signal('Ada');
const lastName = signal('Lovelace');

const fullName = computed(() => `${firstName.value} ${lastName.value}`, 'fullName');
console.log(fullName.value); // 'Ada Lovelace'

firstName.value = 'Augusta';
console.log(fullName.value); // 'Augusta Lovelace'