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
Dmitriy Pleshevskiy 49aac94675 fix: use window location as base url
chore: add dist folder to repo
chore(deps): add node-fetch for tests
chore: change prepare request visibility
chore: add tests for prepare request method
chore: update example

Closes #20
2020-12-08 10:35:18 +03:00

44 lines
1.4 KiB
TypeScript

import { ClientResponse } from './client';
export declare type RequestState<R> = Readonly<{
data: R | null;
loading: boolean;
isCalled: boolean;
prevHeaders?: Record<string, string>;
prevVariables?: Record<string, any>;
prevParams?: Record<string, any>;
}>;
export declare type PublicRequestState<R> = Pick<RequestState<R>, 'data' | 'loading' | 'isCalled'>;
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>;
};
export declare function requestReducer<R>(state: RequestState<R>, action: RequestAction<R>): {
loading: boolean;
isCalled: boolean;
prevHeaders: Record<string, string>;
prevVariables: Record<string, any>;
prevParams: Record<string, any> | undefined;
data: R | null;
} | {
loading: boolean;
data: R;
isCalled: boolean;
prevHeaders?: Record<string, string> | undefined;
prevVariables?: Record<string, any> | undefined;
prevParams?: Record<string, any> | undefined;
} | {
loading: boolean;
data: null;
isCalled: boolean;
prevHeaders?: Record<string, string> | undefined;
prevVariables?: Record<string, any> | undefined;
prevParams?: Record<string, any> | undefined;
};