This repository has been archived on 2023-03-02. You can view files and clone it, but cannot push or open issues or pull requests.
react-rest-request/target/reducer.d.ts

35 lines
1.1 KiB
TypeScript
Raw Normal View History

/// <reference types="react" />
import { ClientResponse } from './client';
2021-06-23 02:30:19 +03:00
export interface PublicRequestState<R> {
readonly data: R | null;
readonly loading: boolean;
readonly isCalled: boolean;
readonly isCanceled?: boolean;
readonly response?: ClientResponse<R>;
readonly fetchError?: Error;
}
export interface RequestState<R> extends PublicRequestState<R> {
readonly prevHeaders?: Record<string, string>;
readonly prevVariables?: Record<string, any>;
readonly prevParams?: Record<string, any>;
}
export declare type RequestAction<R> = {
type: 'call';
headers: Record<string, string>;
variables: Record<string, any>;
params?: Record<string, any>;
} | {
type: 'success';
response: ClientResponse<R>;
} | {
type: 'failure';
response: ClientResponse<R>;
} | {
type: 'cancel';
2021-06-23 02:30:19 +03:00
} | {
type: 'clearStore';
};
export declare type RequestReducer<R> = React.Reducer<RequestState<R>, RequestAction<R>>;
2021-06-23 02:30:19 +03:00
export declare const INITIAL_REQUEST_STATE: RequestState<any>;
2021-06-17 22:43:29 +03:00
export declare function requestReducer<R>(state: RequestState<R>, action: RequestAction<R>): RequestState<R>;