class LazyComputed
implements LazyDependant
import { LazyComputed } from "https://deno.land/x/tui@2.1.11/src/signals/mod.ts";
LazyComputed is a type of signal that depends on other signals and updates when any of them changes
- If time between updates is smaller than given interval it gets delayed
- If given
Flusher
instead, it will update afterFlusher.flush()
gets called - Both interval and
Flusher
might be set at the same time.
Examples
Example 1
Example 1
const multiplicand = new Signal(1);
const multiplier = new Signal(2);
const product = new LazyComputed(() => multiplicand.value * multiplier.value, 16);
console.log(product.value); // 2
await Promise.resolve(); // Dependency tracking is asynchronous read more in `dependency_tracking.ts`
multiplicand.value = 2;
console.log(product.value); // 2
multiplier.value = 7;
console.log(product.value); // 2
setTimeout(() => {
console.log(product.value); // 14
}, 16)
Constructors
new
LazyComputed(computable: Computable<T>, interval: number)new
LazyComputed(computable: Computable<T>, flusher: Flusher)new
LazyComputed(computable: Computable<T>, options: LazyComputedOptions)new
LazyComputed(computable: Computable<T>, option: LazyComputedOptions | number | Flusher)Methods
update(cause: Dependency): void