videx-3d
Version:
React 3D component library designed for sub surface visualizations in the browser
55 lines (54 loc) • 1.89 kB
TypeScript
import { KeyType, Store } from './Store';
/**
* Used internally by DataLoader class
*/
export type BatchQueueEntry = {
key: KeyType;
promise: Promise<any>;
_resolve: ((value?: any) => void) | null;
};
/**
* Loader Config
*/
export type LoaderConfig = {
preloaded?: boolean;
batched?: boolean;
batchSize?: number;
batchMaxDelay?: number;
noCache?: boolean;
transform?: (record: any) => any;
init?: <T>(...args: any[]) => Promise<[KeyType, T][]>;
load?: <T>(id: KeyType, args?: any) => Promise<T | null>;
batchLoad?: <T>(...args: any[]) => Promise<[KeyType, T][]>;
};
/**
* This is a helper class that may be used to simplify implementation
* of the Store interface. The Store may be implemented as you wish, as
* long as it adapts to the interface, but this class can be useful for
* managing loading on demand, caching, preloading and more.
*
* You would typically build your store to hold a loader instance per
* data type. See the implementation of the MockStore for example usage.
*
* The DataLoader has the following features:
* - optional caching of data
* - preload complete data set or on-demand loading of data (single record or batched)
* - promise sharing of multiple requests for the same data record
*/
export declare class DataLoader {
store: Store;
config: LoaderConfig;
cached: Map<KeyType, unknown>;
private _activeLoaders;
private _batchqueue;
private _flushScheduled;
constructor(store: Store, config?: LoaderConfig);
init(...args: any[]): Promise<boolean>;
all<T>(): Promise<T[] | null>;
_enqueueRequest(key: KeyType): Promise<any>;
_processBatch(batch: BatchQueueEntry[]): Promise<null | undefined>;
_processBatchQueue(): Promise<void>;
get<T>(key: KeyType, args?: any): Promise<T | null>;
set<T>(key: KeyType, value: T): void;
clear(): void;
}