Skip to content

Commit

Permalink
feat: cache restful api objects
Browse files Browse the repository at this point in the history
  • Loading branch information
dantio committed May 31, 2020
1 parent 2e735e6 commit 45220b9
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/api/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Api from './restful/';
import {Browse, Buy, Feed, Marketing as BuyMarketing, Offer, Order} from './restful/buy';
import {Catalog, Commerce, Identity, Taxonomy, Translation} from './restful/commerce';
import {Analytics as DeveloperAnalytics, Developer} from './restful/developer';
import {Cancellation, Case, Inquiry, PostOrder, Return} from './restful/postOrder/index';
import {Cancellation, Case, Inquiry, PostOrder, Return} from './restful/postOrder';
import {
Account,
Analytics as SellAnalytics,
Expand All @@ -27,6 +27,7 @@ export default class Factory {
public readonly req: ILimitedRequest;

private _traditional?: Traditional;
private _restful: any = {}

constructor(
auth: Auth,
Expand Down Expand Up @@ -112,6 +113,7 @@ export default class Factory {

// tslint:disable-next-line:variable-name
private createRestfulApi<T extends Api>(ApiClass: new (auth: Auth) => T): T {
return new ApiClass(this.auth);
const name = ApiClass.constructor.name
return this._restful[name] || (this._restful[name] = new ApiClass(this.auth));
}
}

0 comments on commit 45220b9

Please sign in to comment.