mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Add this.getRequestOptions default
Signed-off-by: Panu Horsmalahti <phorsmalahti@mirantis.com>
This commit is contained in:
parent
6e08008630
commit
ee11bc5600
@ -69,13 +69,13 @@ export class JsonApi<D = JsonApiData, P extends JsonApiParams = JsonApiParams> {
|
|||||||
this.config = Object.assign({}, JsonApi.configDefault, config);
|
this.config = Object.assign({}, JsonApi.configDefault, config);
|
||||||
this.reqInit = merge({}, JsonApi.reqInitDefault, reqInit);
|
this.reqInit = merge({}, JsonApi.reqInitDefault, reqInit);
|
||||||
this.parseResponse = this.parseResponse.bind(this);
|
this.parseResponse = this.parseResponse.bind(this);
|
||||||
this.getRequestOptions = config.getRequestOptions;
|
this.getRequestOptions = config.getRequestOptions ?? (() => Promise.resolve({}));
|
||||||
}
|
}
|
||||||
|
|
||||||
public onData = new EventEmitter<[D, Response]>();
|
public onData = new EventEmitter<[D, Response]>();
|
||||||
public onError = new EventEmitter<[JsonApiErrorParsed, Response]>();
|
public onError = new EventEmitter<[JsonApiErrorParsed, Response]>();
|
||||||
|
|
||||||
private getRequestOptions?: JsonApiConfig["getRequestOptions"];
|
private getRequestOptions: JsonApiConfig["getRequestOptions"];
|
||||||
|
|
||||||
get<T = D>(path: string, params?: P, reqInit: RequestInit = {}) {
|
get<T = D>(path: string, params?: P, reqInit: RequestInit = {}) {
|
||||||
return this.request<T>(path, params, { ...reqInit, method: "get" });
|
return this.request<T>(path, params, { ...reqInit, method: "get" });
|
||||||
@ -86,7 +86,7 @@ export class JsonApi<D = JsonApiData, P extends JsonApiParams = JsonApiParams> {
|
|||||||
const reqInit: RequestInit = merge(
|
const reqInit: RequestInit = merge(
|
||||||
{},
|
{},
|
||||||
this.reqInit,
|
this.reqInit,
|
||||||
this.getRequestOptions ? (await this.getRequestOptions()) : {},
|
await this.getRequestOptions(),
|
||||||
init
|
init
|
||||||
);
|
);
|
||||||
const { query } = params || {} as P;
|
const { query } = params || {} as P;
|
||||||
@ -125,7 +125,7 @@ export class JsonApi<D = JsonApiData, P extends JsonApiParams = JsonApiParams> {
|
|||||||
const reqInit: RequestInit = merge(
|
const reqInit: RequestInit = merge(
|
||||||
{},
|
{},
|
||||||
this.reqInit,
|
this.reqInit,
|
||||||
this.getRequestOptions ? (await this.getRequestOptions()) : {},
|
await this.getRequestOptions(),
|
||||||
init
|
init
|
||||||
);
|
);
|
||||||
const { data, query } = params || {} as P;
|
const { data, query } = params || {} as P;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user