@weapnl/js-junction 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,9 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## v0.0.7
6
+ - Request cancel improvements.
7
+
5
8
  ## v0.0.6
6
9
  - Added support for request cancellation by key.
7
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@weapnl/js-junction",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "description": "This project allows you to easily consume API's built with Junction.",
5
5
  "main": "./src/index.js",
6
6
  "scripts": {
@@ -116,6 +116,8 @@ export default class Model extends Request {
116
116
  * @returns {this[]} List of models.
117
117
  */
118
118
  async index () {
119
+ this._connection.cancelRunning(this);
120
+
119
121
  this._response = await this._connection.get(
120
122
  this._queryString(),
121
123
  this.bodyParameters,
@@ -146,6 +148,8 @@ export default class Model extends Request {
146
148
 
147
149
  if (! identifier) return null;
148
150
 
151
+ this._connection.cancelRunning(this);
152
+
149
153
  this._response = await this._connection.get(
150
154
  this._queryString(identifier),
151
155
  this.bodyParameters,
@@ -170,6 +174,8 @@ export default class Model extends Request {
170
174
  * @returns {this} The created model.
171
175
  */
172
176
  async store (extraData = {}) {
177
+ this._connection.cancelRunning(this);
178
+
173
179
  this._response = await this._connection.post(
174
180
  this._queryString(),
175
181
  { ...this._attributes.toJson(this), ...extraData },
@@ -194,6 +200,8 @@ export default class Model extends Request {
194
200
  * @returns {this} The updated model.
195
201
  */
196
202
  async update (extraData = {}) {
203
+ this._connection.cancelRunning(this);
204
+
197
205
  this._response = await this._connection.put(
198
206
  this._queryString(this._identifier),
199
207
  { ...this._attributes.toJson(this), ...extraData },
@@ -216,6 +224,8 @@ export default class Model extends Request {
216
224
  * @returns {boolean} Whether the deletion was successful.
217
225
  */
218
226
  async destroy () {
227
+ this._connection.cancelRunning(this);
228
+
219
229
  this._response = await this._connection.delete(
220
230
  this._queryString(this._identifier),
221
231
  );
package/src/connection.js CHANGED
@@ -11,8 +11,6 @@ export default class Connection {
11
11
  this.running = false;
12
12
  this.canceled = false;
13
13
  this.failed = false;
14
-
15
- this._request = null;
16
14
  }
17
15
 
18
16
  cancel () {
@@ -23,8 +21,8 @@ export default class Connection {
23
21
  this.canceled = true;
24
22
  }
25
23
 
26
- setRequest (request) {
27
- this._request = request;
24
+ cancelRunning (request) {
25
+ this._api.cancelRunning(request);
28
26
  }
29
27
 
30
28
  setConfig (config) {
@@ -58,8 +56,6 @@ export default class Connection {
58
56
  url = `/${url}`;
59
57
  }
60
58
 
61
- this._api.cancelRunning(this._request);
62
-
63
59
  const config = {
64
60
  url: (this._api ? this._api.baseUrl : api.baseUrl) + url,
65
61
  method,
package/src/request.js CHANGED
@@ -32,7 +32,6 @@ export default class Request {
32
32
  this._onForbidden = () => {};
33
33
 
34
34
  this._connection = new Connection();
35
- this._connection.setRequest(this);
36
35
 
37
36
  this._response = null;
38
37
  this.key = null;
@@ -74,6 +73,8 @@ export default class Request {
74
73
  async get () {
75
74
  const url = this.url ?? this.constructor.endpoint;
76
75
 
76
+ this._connection.cancelRunning(this);
77
+
77
78
  this._response = await this._connection.get(
78
79
  url,
79
80
  this.bodyParameters,
@@ -92,6 +93,8 @@ export default class Request {
92
93
  async post (data = {}) {
93
94
  const url = this.url ?? this.constructor.endpoint;
94
95
 
96
+ this._connection.cancelRunning(this);
97
+
95
98
  this._response = await this._connection.post(
96
99
  url,
97
100
  data,
@@ -110,6 +113,8 @@ export default class Request {
110
113
  async put (data = {}) {
111
114
  const url = this.url ?? this.constructor.endpoint;
112
115
 
116
+ this._connection.cancelRunning(this);
117
+
113
118
  this._response = await this._connection.put(
114
119
  url,
115
120
  { ...data, ...this.bodyParameters },
@@ -126,6 +131,8 @@ export default class Request {
126
131
  async delete () {
127
132
  const url = this.url ?? this.constructor.endpoint;
128
133
 
134
+ this._connection.cancelRunning(this);
135
+
129
136
  this._response = await this._connection.delete(
130
137
  url,
131
138
  );
@@ -144,6 +151,8 @@ export default class Request {
144
151
  async storeFiles (files = {}, data = {}) {
145
152
  const url = this.url ?? this.constructor.endpoint;
146
153
 
154
+ this._connection.cancelRunning(this);
155
+
147
156
  this._connection.setConfig({
148
157
  headers: {
149
158
  'Content-Type': 'multipart/form-data',