UNPKG

badmfck-signal

Version:

An implementation of a signaling mechanism used to connect components and transfer data between them

47 lines (45 loc) 1.25 kB
import { Binder } from "./Binder"; interface IError { code: number; message: string; } export interface IExecutorResponse<T> { data: T | null; error?: IError; } export interface IExecutorOptions { cacheTime: number; } /** K - request type T - data type */ export declare class DataProvider<K, T> { private response; private busy; private options; private lastFetchTime; private callbacks; private subscribers; private name; private executor; private defaultNotificator; private lastRequestHash; static nextID: number; constructor(opt?: IExecutorOptions, name?: string); reset(): void; isBusy(): boolean; isEmpty(): boolean; setExecutor(executor: (req?: K) => Promise<IExecutorResponse<T>>): DataProvider<K, T>; getData(): T | null; setOptions(opt: IExecutorOptions): void; getError(): IError | null; setDefaultNotificator(notificator: Binder<K, T | IError | null> | null): DataProvider<K, T>; /** Subscribe to data loading complete event. will fire response and remove subscribtion */ subscribe(cb: (response: IExecutorResponse<T>) => void): void; load(req?: K): Promise<IExecutorResponse<T>>; } export {};