react-antd-admin-panel
Version:
Modern TypeScript-first React admin panel builder with Ant Design 6
89 lines • 2.68 kB
TypeScript
import { Get } from './Get';
import { Post } from './Post';
export interface LoaderData<T = any> {
[key: string]: T;
}
export interface LoaderHooks {
onBeforeLoad?: () => void | Promise<void>;
onLoad?: (data: LoaderData) => void | Promise<void>;
onAfterLoad?: (data: LoaderData) => void | Promise<void>;
onError?: (error: Error) => void | Promise<void>;
}
export interface LoaderRequest<T = any> {
key: string;
request: Get<T> | Post<any, T>;
required?: boolean;
condition?: (data: LoaderData) => boolean;
}
/**
* Loader - Data pre-fetching orchestrator for page lifecycle
* Manages multiple HTTP requests with dependencies and conditions
*
* @example
* const loader = new Loader()
* .add('user', new Get().target('/api/user'))
* .add('posts', new Get().target('/api/posts'), {
* condition: (data) => data.user?.isAdmin
* })
* .onLoad((data) => console.log('Loaded:', data))
* .execute();
*/
export declare class Loader {
private _requests;
private _hooks;
private _parallel;
private _abortOnError;
/**
* Add a request to the loader
*/
add<T = any>(key: string, request: Get<T> | Post<any, T>, options?: {
required?: boolean;
condition?: (data: LoaderData) => boolean;
}): this;
/**
* Set whether requests execute in parallel (default) or sequentially
*/
parallel(value?: boolean): this;
/**
* Set whether to abort on first error (default: false)
*/
abortOnError(value?: boolean): this;
/**
* Hook called before any requests are made
*/
onBeforeLoad(callback: () => void | Promise<void>): this;
/**
* Hook called after all requests complete successfully
*/
onLoad(callback: (data: LoaderData) => void | Promise<void>): this;
/**
* Hook called after onLoad (useful for side effects)
*/
onAfterLoad(callback: (data: LoaderData) => void | Promise<void>): this;
/**
* Hook called if any request fails
*/
onError(callback: (error: Error) => void | Promise<void>): this;
/**
* Execute all requests with lifecycle management
*/
execute(): Promise<LoaderData>;
/**
* Execute requests in parallel
*/
private _executeParallel;
/**
* Execute requests sequentially (allows conditions to depend on previous results)
*/
private _executeSequential;
/**
* Create a loader from a configuration object
*/
static from(config: {
requests: LoaderRequest[];
hooks?: LoaderHooks;
parallel?: boolean;
abortOnError?: boolean;
}): Loader;
}
//# sourceMappingURL=Loader.d.ts.map