chore: some cosmetic changes

This commit is contained in:
Dmitriy Pleshevskiy 2021-05-16 23:19:02 +03:00
parent 304611fb53
commit 00308d6718

View file

@ -2,11 +2,11 @@ import invariant from 'tiny-invariant';
import { Method } from './endpoint'; import { Method } from './endpoint';
import { formDataFromObject, isFunction, urlSearchParamsFromObject } from './misc'; import { formDataFromObject, isFunction, urlSearchParamsFromObject } from './misc';
export type ClientConfig = { export interface ClientConfig {
baseUrl: string, baseUrl: string,
} }
type PrepareRequestProps = { export interface PrepareRequestProps {
url: string, url: string,
method: Method, method: Method,
headers: Record<string, string>, headers: Record<string, string>,
@ -28,9 +28,9 @@ export type ClientResponse<Data extends Record<string, any>> =
export class Client { export class Client {
private controller = new AbortController(); private controller = new AbortController();
constructor(private config: ClientConfig) {} constructor(private readonly config: ClientConfig) {}
public prepareRequest(props: PrepareRequestProps) { prepareRequest(props: PrepareRequestProps) {
const requestCanContainBody = [Method.POST, Method.PATCH, Method.PUT].includes(props.method); const requestCanContainBody = [Method.POST, Method.PATCH, Method.PUT].includes(props.method);
const defaultBaseUrl = (window as Window | undefined)?.location.href; const defaultBaseUrl = (window as Window | undefined)?.location.href;
@ -79,7 +79,7 @@ export class Client {
); );
} }
public request<Data extends Record<string, any>>( request<Data extends Record<string, any>>(
{ {
transformResponseData, transformResponseData,
...restProps ...restProps
@ -132,7 +132,7 @@ export class Client {
}); });
} }
public cancelRequest() { cancelRequest() {
this.controller.abort(); this.controller.abort();
this.controller = new AbortController(); this.controller = new AbortController();
} }