Skip to content

Commit 4e33443

Browse files
author
Crhistian Ramirez
committed
🐛 bind "this" for all class methods
this ensures "this" is never lost if context changes
1 parent ceb81ed commit 4e33443

38 files changed

Lines changed: 603 additions & 1 deletion

codegen/templates/api/_RESOURCE_.ts.hbs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ import httpClient from '../utils/HttpClient';
99
class {{resource.id}} {
1010
private impersonating:boolean = false;
1111

12+
/**
13+
* @ignore
14+
* not part of public api, don't include in generated docs
15+
*/
16+
constructor() {
17+
{{#resource.operations}}
18+
this.{{name}} = this.{{name}}.bind(this);
19+
{{/resource.operations}}
20+
}
21+
1222
{{#resource.operations}}
1323
/**{{#allParams}}
1424
* @param {{#if isQueryParam}}options.{{name}} {{description}}{{else}}{{name}} {{description}}{{#if isBodyParam}}{{#if hasRequiredFields}}Required fields: {{commaSeparate requiredFields}}{{/if}}{{/if}}{{/if}}{{/allParams}}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "ordercloud-javascript-sdk",
33
"description": "The offical Javascript SDK for the Ordercloud ecommerce API",
44
"author": "Four51 OrderCloud",
5-
"version": "4.0.0-3",
5+
"version": "4.0.0-2",
66
"main": "dist/index.js",
77
"module": "dist/index.esm.js",
88
"types": "dist/index.d.ts",

src/api/Addresses.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,22 @@ import httpClient from '../utils/HttpClient';
99
class Addresses {
1010
private impersonating:boolean = false;
1111

12+
/**
13+
* @ignore
14+
* not part of public api, don't include in generated docs
15+
*/
16+
constructor() {
17+
this.List = this.List.bind(this);
18+
this.Create = this.Create.bind(this);
19+
this.Get = this.Get.bind(this);
20+
this.Save = this.Save.bind(this);
21+
this.Delete = this.Delete.bind(this);
22+
this.Patch = this.Patch.bind(this);
23+
this.DeleteAssignment = this.DeleteAssignment.bind(this);
24+
this.ListAssignments = this.ListAssignments.bind(this);
25+
this.SaveAssignment = this.SaveAssignment.bind(this);
26+
}
27+
1228
/**
1329
* @param buyerID ID of the buyer.
1430
* @param options.search Word or phrase to search for.

src/api/AdminAddresses.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,19 @@ import httpClient from '../utils/HttpClient';
88
class AdminAddresses {
99
private impersonating:boolean = false;
1010

11+
/**
12+
* @ignore
13+
* not part of public api, don't include in generated docs
14+
*/
15+
constructor() {
16+
this.List = this.List.bind(this);
17+
this.Create = this.Create.bind(this);
18+
this.Get = this.Get.bind(this);
19+
this.Save = this.Save.bind(this);
20+
this.Delete = this.Delete.bind(this);
21+
this.Patch = this.Patch.bind(this);
22+
}
23+
1124
/**
1225
* @param options.search Word or phrase to search for.
1326
* @param options.searchOn Comma-delimited list of fields to search on.

src/api/AdminUserGroups.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,22 @@ import httpClient from '../utils/HttpClient';
99
class AdminUserGroups {
1010
private impersonating:boolean = false;
1111

12+
/**
13+
* @ignore
14+
* not part of public api, don't include in generated docs
15+
*/
16+
constructor() {
17+
this.List = this.List.bind(this);
18+
this.Create = this.Create.bind(this);
19+
this.Get = this.Get.bind(this);
20+
this.Save = this.Save.bind(this);
21+
this.Delete = this.Delete.bind(this);
22+
this.Patch = this.Patch.bind(this);
23+
this.DeleteUserAssignment = this.DeleteUserAssignment.bind(this);
24+
this.ListUserAssignments = this.ListUserAssignments.bind(this);
25+
this.SaveUserAssignment = this.SaveUserAssignment.bind(this);
26+
}
27+
1228
/**
1329
* @param options.search Word or phrase to search for.
1430
* @param options.searchOn Comma-delimited list of fields to search on.

src/api/AdminUsers.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,19 @@ import httpClient from '../utils/HttpClient';
88
class AdminUsers {
99
private impersonating:boolean = false;
1010

11+
/**
12+
* @ignore
13+
* not part of public api, don't include in generated docs
14+
*/
15+
constructor() {
16+
this.List = this.List.bind(this);
17+
this.Create = this.Create.bind(this);
18+
this.Get = this.Get.bind(this);
19+
this.Save = this.Save.bind(this);
20+
this.Delete = this.Delete.bind(this);
21+
this.Patch = this.Patch.bind(this);
22+
}
23+
1124
/**
1225
* @param options.search Word or phrase to search for.
1326
* @param options.searchOn Comma-delimited list of fields to search on.

src/api/ApiClients.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,23 @@ import httpClient from '../utils/HttpClient';
99
class ApiClients {
1010
private impersonating:boolean = false;
1111

12+
/**
13+
* @ignore
14+
* not part of public api, don't include in generated docs
15+
*/
16+
constructor() {
17+
this.List = this.List.bind(this);
18+
this.Create = this.Create.bind(this);
19+
this.Get = this.Get.bind(this);
20+
this.Save = this.Save.bind(this);
21+
this.Delete = this.Delete.bind(this);
22+
this.Patch = this.Patch.bind(this);
23+
this.ListAssignments = this.ListAssignments.bind(this);
24+
this.SaveAssignment = this.SaveAssignment.bind(this);
25+
this.DeleteBuyerAssignment = this.DeleteBuyerAssignment.bind(this);
26+
this.DeleteSupplierAssignment = this.DeleteSupplierAssignment.bind(this);
27+
}
28+
1229
/**
1330
* @param options.search Word or phrase to search for.
1431
* @param options.searchOn Comma-delimited list of fields to search on.

src/api/ApprovalRules.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,19 @@ import httpClient from '../utils/HttpClient';
88
class ApprovalRules {
99
private impersonating:boolean = false;
1010

11+
/**
12+
* @ignore
13+
* not part of public api, don't include in generated docs
14+
*/
15+
constructor() {
16+
this.List = this.List.bind(this);
17+
this.Create = this.Create.bind(this);
18+
this.Get = this.Get.bind(this);
19+
this.Save = this.Save.bind(this);
20+
this.Delete = this.Delete.bind(this);
21+
this.Patch = this.Patch.bind(this);
22+
}
23+
1124
/**
1225
* @param buyerID ID of the buyer.
1326
* @param options.search Word or phrase to search for.

src/api/Buyers.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,19 @@ import httpClient from '../utils/HttpClient';
88
class Buyers {
99
private impersonating:boolean = false;
1010

11+
/**
12+
* @ignore
13+
* not part of public api, don't include in generated docs
14+
*/
15+
constructor() {
16+
this.List = this.List.bind(this);
17+
this.Create = this.Create.bind(this);
18+
this.Get = this.Get.bind(this);
19+
this.Save = this.Save.bind(this);
20+
this.Delete = this.Delete.bind(this);
21+
this.Patch = this.Patch.bind(this);
22+
}
23+
1124
/**
1225
* @param options.search Word or phrase to search for.
1326
* @param options.searchOn Comma-delimited list of fields to search on.

src/api/Catalogs.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,25 @@ import httpClient from '../utils/HttpClient';
1010
class Catalogs {
1111
private impersonating:boolean = false;
1212

13+
/**
14+
* @ignore
15+
* not part of public api, don't include in generated docs
16+
*/
17+
constructor() {
18+
this.List = this.List.bind(this);
19+
this.Create = this.Create.bind(this);
20+
this.Get = this.Get.bind(this);
21+
this.Save = this.Save.bind(this);
22+
this.Delete = this.Delete.bind(this);
23+
this.Patch = this.Patch.bind(this);
24+
this.DeleteAssignment = this.DeleteAssignment.bind(this);
25+
this.DeleteProductAssignment = this.DeleteProductAssignment.bind(this);
26+
this.ListAssignments = this.ListAssignments.bind(this);
27+
this.SaveAssignment = this.SaveAssignment.bind(this);
28+
this.ListProductAssignments = this.ListProductAssignments.bind(this);
29+
this.SaveProductAssignment = this.SaveProductAssignment.bind(this);
30+
}
31+
1332
/**
1433
* @param options.search Word or phrase to search for.
1534
* @param options.searchOn Comma-delimited list of fields to search on.

0 commit comments

Comments
 (0)