export type LoadState = 'unloaded' | 'loading' | 'loaded' | 'error'; export interface DataPage { page: number; page_size: number; page_count: number; total_count: number; unfiltered_count?: number; sort?: string; items: T[]; } export interface DataFetcherOptions { /** Debounce time or `false`. Default 250ms */ debounce?: number | false; /** * Maximum amount of time to spend debouncing before issuing a request. * Requires `incremental: true` */ max_debounce?: number | false; /** * If set, this fetcher will not be allowed to trigger more than once within the specified number of milliseconds. */ throttle?: false | number; /** * Initial value of the fetcher. * If not `null`, the fetcher will begin in `loaded` state and not trigger a fetch until parameters change or explicitly requested. */ initial?: D; /** * Parameters to assume upon initialization. */ initialParams?: any; /** * When true, even activated fetchers won't call `fetch` until something accesses `.data` */ lazy?: boolean; /** * Determines when the DataFetcher "goes active". Until it is active, it will not call the given `fetch` function. * - true: Activate the DataFetcher immediately * - false: Will not activate by itself; you must call .activate() * - 'queried': Will activate the first time something attempts to read `.data` * - 'requested': (Default) Will activate when explicitly requested, or when a parameter is changed with `.updateParam[s]()` */ activate?: boolean | 'queried' | 'requested'; /** * If a prior fetch returns after another one is triggered (but not resolved), should its result be kept (true) or discarded (false)? * The default is based on `max_debounce`. */ incremental?: boolean; } type ROAnyObject = { readonly [k: string]: any; }; /** * Helper for making data/async requests * * Allows for clean declaration of what data a Component uses and has built-in error handling. * Integrates MobX to allow components to re-render when data has loaded/errored/etc. * * It can keep track of parameters (eg page number, sort order) and will refetch (with a debounce) whenever a parameter is changed. */ export declare class DataFetcher { constructor(fetch: (params: any) => PromiseLike, opts?: DataFetcherOptions); duplicate(override_options?: DataFetcherOptions): this; private emitter; on: { (event: E, f: (...params: { params_changed: [params: any, changedKeys: string[]]; fetched: []; }[E]) => void): any; (events: E_1[], f: (...params: { params_changed: [params: any, changedKeys: string[]]; fetched: []; }[E_1]) => void): any; }; off: { (event: E, f: (...params: { params_changed: [params: any, changedKeys: string[]]; fetched: []; }[E]) => void): any; (events: E_1[], f: (...params: { params_changed: [params: any, changedKeys: string[]]; fetched: []; }[E_1]) => void): any; }; private transactor; /** * Wait until the Transactor is caught up to any already-triggered triggers. * Has the same effect as `catchupToAll()` if `incremental: false`. */ catchupToCurrent(): Promise; /** Wait until the Transactor has no pending triggers */ catchupToAll(): Promise; private readonly options; fetchFunc: (params: any) => PromiseLike; private activated; private queried; private accessor _desiredParams; private accessor _currentParams; accessor _data: D; accessor currentError: Error; accessor currentStatus: LoadState; accessor fetchStatus: LoadState; get desiredParams(): ROAnyObject; get currentParams(): ROAnyObject; get data(): D; get outdated(): boolean; activate(): void; updateParams(p: any): void; updateParam(k: any, v: any): void; private triggerLazyFetch; /** *@deprecated Only use was with activate: "requested", but explicit `activate()` seems to be the better approach - * in fact, all observed uses of `requestRefetch()` are in `componentDidMount` */ requestRefetch(): void; /** * Mark the DataFetcher as dirty and request a refetch. */ forceRefetch(skip_debounce?: boolean): void; manualSet(value: D): void; private updateCurrentStatus; } export interface LocallySortedDataFetcherOptions extends DataFetcherOptions> { sorts?: Record number>; default_sort?: string; default_page_size?: number; } /** * DataFetcher subclass that expects to receive the complete dataset and applies pagination and sorting locally. * Mainly intended for more legacy applications */ export declare class LocallySortedDataFetcher extends DataFetcher> { protected _fetch: (params: any) => PromiseLike>; constructor(_fetch: (params: any) => PromiseLike>, opts?: LocallySortedDataFetcherOptions); protected sorts: LocallySortedDataFetcherOptions['sorts']; protected default_sort: string; protected default_page_size: number; private last_params; private last_fetched; private last_sort; protected sorting_fetch(params: any): Promise>; manualSet(value: DataPage): void; protected getPagedData(): DataPage; forceRefetch(): void; } export {};