UNPKG

jinaga

Version:

Data management for web and mobile applications.

80 lines 3.25 kB
import { FactManager } from "../managers/factManager"; import { Specification } from "../specification/specification"; import { FactReference, ProjectedResult } from "../storage"; export type ResultAddedFunc<U> = (value: U) => Promise<() => Promise<void>> | // Asynchronous with removal function Promise<void> | // Asynchronous without removal function (() => void) | // Synchronous with removal function void; export interface ObservableCollection<T> { onAdded(handler: ResultAddedFunc<T>): void; } export interface Observer<T> { cached(): Promise<boolean>; loaded(): Promise<void>; /** * Returns a promise that resolves when all pending notifications have been processed. * This includes all observer callbacks triggered by facts that have been added. * Useful in tests to wait for async operations to complete. */ processed(): Promise<void>; stop(): void; } export declare class ObserverImpl<T> implements Observer<T> { private factManager; private given; private specification; private givenHash; private cachedPromise; private loadedPromise; private listeners; private removalsByTuple; private notifiedTuples; private addedHandlers; private specificationHash; private feeds; private stopped; private listenersAdded; /** * Tracks all pending notification promises to enable waiting for processing completion. */ private pendingNotifications; /** * Buffers results that are pending delivery to result handlers. * * The key is a string in the format `path|tupleHash`, where: * - `path` is a string representing the traversal path in the specification. * - `tupleHash` is the hash of the tuple of fact references for the current context. * * The value is an object containing: * - `projection`: The projection associated with the results. * - `parentSubset`: The parent subset of fact references. * - `results`: The buffered results (of type `ProjectedResult[]`) to be replayed to handlers when they are registered. * * This map is used to buffer results that are produced before any handlers are registered, * enabling replay of results to late-registered handlers. */ private pendingAddsByKey; constructor(factManager: FactManager, given: FactReference[], specification: Specification, resultAdded: ResultAddedFunc<T>); start(keepAlive: boolean): void; private addSpecificationListeners; cached(): Promise<boolean>; loaded(): Promise<void>; processed(): Promise<void>; stop(): void; private fetch; private read; private onResult; private notifyAdded; notifyRemoved(resultSubset: string[], projectedResult: ProjectedResult[]): Promise<void>; /** * Buffers a pending notification for replay when a handler is registered later. * * @param path - The path in the specification * @param pr - The projected result to buffer * @param projection - The projection associated with the result * @param parentSubset - The parent subset of fact references */ private bufferPendingNotification; private injectObservers; } //# sourceMappingURL=observer.d.ts.map