Skip to main content
Module

x/tui/mod.ts>LazyEffect

🦕 Deno module for creating Terminal User Interfaces
Latest
class LazyEffect
implements LazyDependant
extends Effect
import { LazyEffect } from "https://deno.land/x/tui@2.1.11/mod.ts";

LazyEffect is an container for callback function, which runs every time any of its dependencies get updated. When initialized that functions gets ran and all dependencies for it are tracked.

  • If time between updates is smaller than given interval it gets delayed
  • If given Flusher instead, it will update after Flusher.flush() gets called
  • Both interval and Flusher might be set at the same time.

Examples

Example 1

const name = new Signal("Jonathan");
const lazyEffect = new LazyEffect(() => {
 console.log("Your name is", name.value)
}, 16);
// printed: "Your name is Jonathan"

await Promise.resolve(); // Dependency tracking is asynchronous read more in `dependency_tracking.ts`

name.value = "Brian";
name.value = "Gabriel";
name.value = "Matthew";
// printed: "Your name is Matthew" after 16ms

Constructors

new
LazyEffect(effectable: Effectable, interval: number)
new
LazyEffect(effectable: Effectable, flusher: Flusher)
new
LazyEffect(effectable: Effectable, options: LazyEffectOptions)
new
LazyEffect(effectable: Effectable, option: LazyEffectOptions | number | Flusher)

Properties

optional
flusher: Flusher
optional
interval: number
lastFired: number
optional
timeout: number