@dabapps/redux-requests
Version:
Library for simple redux requests
38 lines (37 loc) • 1.21 kB
TypeScript
import { AxiosError, AxiosResponse } from 'axios';
export declare type Dict<T> = Readonly<{
[key: string]: T;
}>;
export declare type RequestStates = 'REQUEST' | 'SUCCESS' | 'FAILURE';
export declare type UrlMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'OPTIONS' | 'PATCH';
export declare type ExtraMeta = Dict<any>;
export declare type AsyncActionSet = Readonly<{
FAILURE: string;
REQUEST: string;
SUCCESS: string;
}>;
export declare type ResponseState<T = {}> = Readonly<{
requestState: RequestStates | null;
data: AxiosResponse<T> | AxiosError | null;
meta?: ExtraMeta;
}>;
export declare type ResponsesReducerState<T = any> = Dict<Dict<ResponseState<T>>>;
export declare type SetRequestStatePayload = Readonly<{
actionSet: AsyncActionSet;
requestState: RequestStates;
data: any;
tag?: string;
meta?: ExtraMeta;
}>;
export declare type ResetRequestStatePayload = Readonly<{
actionSet: AsyncActionSet;
tag?: string;
}>;
export interface Options {
readonly tag?: string;
shouldRethrow?(errors: AxiosError): boolean;
}
export interface RequestParams extends Options {
readonly metaData?: ExtraMeta;
readonly headers?: Dict<string>;
}