Skip to main content
Module

x/tui/mod.ts>Signal

🦕 Deno module for creating Terminal User Interfaces
Go to Latest
class Signal
implements Dependency
Re-export
import { Signal } from "https://deno.land/x/tui@2.0.0/mod.ts";

Signal wraps value in a container.

Each time you set the value it analyzes whether it changed and propagates update over all of its dependants.

Examples

Example 1

const number = new Signal(0);
number.value++;
console.log(number.value); // 1

Constructors

new
Signal(value: T, options?: SignalOptions<T>)

Properties

protected
$value: T
optional
dependants: Set<Dependant>
optional
forceUpdateValue: boolean
optional
subscriptions: Set<Subscription<T>>
value: T

Methods

depend(dependant: Dependant): void

Add dependant to signal dependants

dispose(): void
  • Overwrites signal's value getter with current value
  • Removes all subscriptions
  • Removes itself from all dependants dependencies
  • If any of the dependant doesn't have any other dependencies it gets disposed
  • Clears dependants
jink(value: T): void

Sets signals value without being appended as dependency

peek(): T

Gets signals value without being appended as dependency

propagate(): void
  • Run all linked subscriptions
  • Update each dependant in dependants
subscribe(subscription: Subscription<T>): void

Bind function to signal, it'll be called each time signal's value changes with current value as argument

toString(): string