Skip to main content
Module

x/tui/mod.ts>Computed

🦕 Deno module for creating Terminal User Interfaces
Latest
class Computed
implements Dependant, Dependency
extends Signal<T>
Re-export
import { Computed } from "https://deno.land/x/tui@2.1.11/mod.ts";

Computed is a type of signal that depends on other signals and updates when any of them changes

Examples

Example 1

const multiplicand = new Signal(1);
const multiplier = new Signal(2);
const product = new Computed(() => multiplicand.value * multiplier.value);

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); // 4
multiplier.value = 7;
console.log(product.value); // 14

Constructors

new
Computed(computable: Computable<T>)

Properties

computable: Computable<T>
dependencies: Set<Dependency>
value: T

Methods

dispose(): void
jink(_value: T): never
update(cause: Dependency | Dependant): void