Interface: SignalComputed<T>
API / @xmachines/play-signals / SignalComputed
Defined in: packages/play-signals/src/types.ts:112
The computed signal. It evaluates late, and it memoizes the result
Signal.Computed tracks each dependency when it runs its callback. It memoizes the result, and it runs the callback again only after a dependency changes. It therefore tracks each dependency for you, and you manage no subscription.
Example
import { Signal } from "@xmachines/play-signals";
const count = new Signal.State(0);const doubled = new Signal.Computed(() => count.get() * 2);
console.log(doubled.get()); // 0count.set(5);console.log(doubled.get()); // 10 (the signal computed it again)console.log(doubled.get()); // 10 (from the memory, with no new computation)Type Parameters
| Type Parameter |
|---|
T |
Methods
get()
get(): T;Defined in: packages/play-signals/src/types.ts:118
Reads the computed value. It computes the value again only after a dependency changed
Returns
T
The value from the current dependencies