UNPKG

rvx

Version:

A signal based rendering library

43 lines 1.09 kB
import { isTracking, Signal } from "../core/signals.js"; export class ProbeSignal extends Signal { #onDisposable; constructor(onDisposable, value) { super(value); this.#onDisposable = onDisposable; } notify() { super.notify(); if (!this.active) { this.#onDisposable(); } } } export class ProbeMap { #probes = new Map(); #get; constructor(get) { this.#get = get; } access(key) { if (isTracking()) { let probe = this.#probes.get(key); if (probe === undefined) { probe = new ProbeSignal(() => this.#probes.delete(key), this.#get(key)); this.#probes.set(key, probe); } probe.access(); } } update(key, value) { const probe = this.#probes.get(key); if (probe !== undefined) { probe.value = value; } } fill(value) { for (const probe of this.#probes.values()) { probe.value = value; } } } //# sourceMappingURL=probes.js.map