///
import { AxiosPromise } from 'axios';
import { ProgressOptions } from '../Progress/useProgress';
import { PlaceholderOptions } from '../Placeholder/Placeholder';
export interface FetcherError {
message: string;
}
export interface FetcherOptions {
errorMessage?: string;
minDelay?: number;
loadingColor?: string;
buttonComponent?: (props: {
doRetry: () => void;
}) => JSX.Element;
loaderComponent?: (props: {
color: string;
}) => JSX.Element;
errorComponent?: (props: {
options: FetcherOptions;
doRetry: () => void;
}) => JSX.Element;
wrapperClassCSS?: string;
loadingClassCSS?: string;
errorClassCSS?: string;
wrapperStyles?: React.CSSProperties;
loadingStyles?: React.CSSProperties;
errorStyles?: React.CSSProperties;
wrapperBackgroundColor?: string;
dimBackground?: boolean;
hideLoader?: boolean;
progress?: {
show?: boolean;
color?: string;
errorColor?: string;
position?: 'top' | 'bottom';
styles?: React.CSSProperties;
} & Partial;
adjustBorderRadius?: boolean;
placeholder?: {
show?: boolean;
} & Partial;
}
export declare type FetcherEvent = 'fetch-start' | 'fetch-end' | 'all-fetch-end' | 'error' | 'loading-forced-start' | 'loading-forced-end' | 'error-forced';
export interface Task {
type: 'fetch' | 'custom';
getPromise: () => AxiosPromise | Promise;
onResult: (data: any) => void;
status: 'pending' | 'failed';
canceled: boolean;
isMultiple: false;
}
export interface ManyTask {
type: 'fetch' | 'custom';
getPromise: () => (AxiosPromise | Promise)[];
onResult: (data: any) => void;
status: 'pending' | 'failed';
canceled: boolean;
isMultiple: true;
}
export declare class FetcherAPI {
loading: boolean;
tasks: (Task | ManyTask)[];
listeners: {
[key: string]: Function[];
};
options: FetcherOptions;
workingCounter: number;
constructor(options?: FetcherOptions);
addListener(event: FetcherEvent, func: Function): void;
removeListener(event: FetcherEvent, func: Function): void;
isBusy(): boolean;
hasFailedTasks(): boolean;
private callListener;
fetch(getResponse: () => AxiosPromise, onResult: (data: T) => void): this;
fetchMany(getResponse: () => AxiosPromise[], onResult: (data: T) => void): Promise;
handle(getPromise: () => Promise, onResult: (result: T) => void): this;
processTask(task: Task): Promise;
processManyTask(task: ManyTask): Promise;
completeTask(task: Task | ManyTask): void;
cancel(): void;
_waitDelay(): Promise;
setLoading(value: boolean): void;
setError(value: FetcherError): void;
retry(): void;
}
export declare function useFetcher(options?: FetcherOptions): FetcherAPI;