UNPKG

lazy-widgets

Version:

Typescript retained mode GUI for the HTML canvas API

35 lines (34 loc) 1.54 kB
import type { Observable } from './Observable.js'; import type { ObservableCallback } from './ObservableCallback.js'; /** * An {@link Observable} which transforms a list of input Observables into a * single value efficiently. * * @category State Management */ export declare class ObservableTransformer<V, I extends Iterable<Observable<U>> | [Observable<U>], U = unknown> implements Observable<V> { readonly inputs: I; readonly transformer: (inputs: I) => V; readonly decider?: ((inputs: I) => boolean) | undefined; private dirty; private cache; private watcher; /** The function callbacks called when the value is changed */ private callbacks; /** * The current value. * * Evaluated when needed. Values are cached. */ get value(): V; /** * @param inputs - The list of observables to use as inputs for this transformer. * @param transformer - The actual transformer function. Takes in a list of input observables, and outputs a single value. * @param decider - Decides whether the transformer's output value needs to be updated or not. If `undefined` (the default), then the value is always assumed to need to be updated whenever an input watcher is invoked. */ constructor(inputs: I, transformer: (inputs: I) => V, decider?: ((inputs: I) => boolean) | undefined); destroy(): void; watch(callback: ObservableCallback<V>, callNow?: boolean, group?: unknown): this; unwatch(callback: ObservableCallback<V>): this; private doCallback; }