@jetlinks-web/core 2.2.5 → 2.2.6
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/package.json +3 -3
- package/src/fetch.ts +16 -9
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jetlinks-web/core",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.6",
|
|
4
4
|
"main": "index.ts",
|
|
5
5
|
"module": "index.ts",
|
|
6
6
|
"keywords": [
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
"axios": "^1.7.4",
|
|
23
23
|
"rxjs": "^7.8.1",
|
|
24
24
|
"@jetlinks-web/constants": "^1.0.9",
|
|
25
|
-
"@jetlinks-web/
|
|
26
|
-
"@jetlinks-web/
|
|
25
|
+
"@jetlinks-web/utils": "^1.2.8",
|
|
26
|
+
"@jetlinks-web/types": "^1.0.2"
|
|
27
27
|
},
|
|
28
28
|
"publishConfig": {
|
|
29
29
|
"registry": "https://registry.npmjs.org/",
|
package/src/fetch.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {getToken} from "@jetlinks-web/utils";
|
|
2
2
|
import {BASE_API, TOKEN_KEY} from "@jetlinks-web/constants";
|
|
3
|
-
import {isFunction, isObject
|
|
3
|
+
import {isFunction, isObject} from "lodash-es";
|
|
4
4
|
import { Observable, } from 'rxjs'
|
|
5
5
|
|
|
6
6
|
const controller = new AbortController();
|
|
7
7
|
|
|
8
|
-
class NdJson {
|
|
8
|
+
export class NdJson {
|
|
9
9
|
options: any = {
|
|
10
10
|
code: 200,
|
|
11
11
|
codeKey: 'status'
|
|
@@ -22,11 +22,10 @@ class NdJson {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
get(url, data = '{}', extra = {}) {
|
|
25
|
+
const _url = this.getUrl(url)
|
|
25
26
|
const that = this
|
|
26
27
|
return new Observable(observer => {
|
|
27
|
-
|
|
28
|
-
const that = this
|
|
29
|
-
|
|
28
|
+
let reader
|
|
30
29
|
fetch(
|
|
31
30
|
_url,
|
|
32
31
|
{
|
|
@@ -37,7 +36,7 @@ class NdJson {
|
|
|
37
36
|
...this.handleRequest(_url)
|
|
38
37
|
}
|
|
39
38
|
).then(resp => {
|
|
40
|
-
|
|
39
|
+
reader = resp.body?.getReader();
|
|
41
40
|
const decoder = new TextDecoder();
|
|
42
41
|
let data_buf = "";
|
|
43
42
|
|
|
@@ -92,6 +91,10 @@ class NdJson {
|
|
|
92
91
|
}).catch(e => {
|
|
93
92
|
observer.error(e)
|
|
94
93
|
})
|
|
94
|
+
|
|
95
|
+
return () => {
|
|
96
|
+
that.cancel()
|
|
97
|
+
}
|
|
95
98
|
})
|
|
96
99
|
}
|
|
97
100
|
|
|
@@ -100,6 +103,7 @@ class NdJson {
|
|
|
100
103
|
const that = this
|
|
101
104
|
|
|
102
105
|
return new Observable(observer => {
|
|
106
|
+
let reader
|
|
103
107
|
fetch(
|
|
104
108
|
_url,
|
|
105
109
|
{
|
|
@@ -111,7 +115,7 @@ class NdJson {
|
|
|
111
115
|
...this.handleRequest(_url)
|
|
112
116
|
}
|
|
113
117
|
).then(async resp => {
|
|
114
|
-
|
|
118
|
+
reader = resp.body?.getReader();
|
|
115
119
|
const decoder = new TextDecoder();
|
|
116
120
|
let data_buf = "";
|
|
117
121
|
|
|
@@ -166,6 +170,10 @@ class NdJson {
|
|
|
166
170
|
}).catch(e => {
|
|
167
171
|
observer.error(e)
|
|
168
172
|
})
|
|
173
|
+
|
|
174
|
+
return () => {
|
|
175
|
+
that.cancel()
|
|
176
|
+
}
|
|
169
177
|
})
|
|
170
178
|
}
|
|
171
179
|
handleRequest(url): RequestInit {
|
|
@@ -213,9 +221,8 @@ class NdJson {
|
|
|
213
221
|
cancel() {
|
|
214
222
|
if (this.isRead) {
|
|
215
223
|
this.isRead = false
|
|
216
|
-
} else {
|
|
217
|
-
controller.abort()
|
|
218
224
|
}
|
|
225
|
+
controller.abort()
|
|
219
226
|
}
|
|
220
227
|
}
|
|
221
228
|
|