import { Effects } from '../Effects'; export declare abstract class Watchable { readonly effects: Effects; protected readonly mapFn: (value: Raw) => Mapped; protected readonly eqFn: (a: Mapped, b: Mapped) => boolean; constructor(effects: Effects, options?: { map?: (value: Raw) => Mapped; eq?: (a: Mapped, b: Mapped) => boolean; }); /** * Fetch the current value, optionally registering a callback for change notification. * The callback should be invoked when the underlying data changes. */ protected abstract fetch(callback?: () => void): Promise; protected abstract readonly label: string; /** * Produce a stream of raw values. Default implementation uses fetch() with * effects callback in a loop. Override for custom subscription mechanisms * (e.g. fs.watch). */ protected produce(abort: AbortSignal): AsyncGenerator; /** * Lifecycle hook called when const() registers a subscription. * Return a cleanup function to be called when the subscription ends. * Override for side effects like FileHelper's consts tracking. */ protected onConstRegistered(_value: Mapped): (() => void) | void; /** * Internal generator that maps raw values and deduplicates using eq. */ private watchGen; /** * Returns the value. Reruns the context from which it has been called if the underlying value changes */ const(): Promise; /** * Returns the value. Does nothing if the value changes */ once(): Promise; /** * Watches the value. Returns an async iterator that yields whenever the value changes */ watch(abort?: AbortSignal): AsyncGenerator; /** * Watches the value. Takes a custom callback function to run whenever the value changes */ onChange(callback: (value: Mapped | undefined, error?: Error) => { cancel: boolean; } | Promise<{ cancel: boolean; }>): void; /** * Watches the value. Returns when the predicate is true */ waitFor(pred: (value: Mapped) => boolean): Promise; }