@ives_xxz/framework 1.6.3 → 1.6.5
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/FW.d.ts +74 -125
- package/Framework.ts +24 -64
- package/FrameworkBase.ts +28 -48
- package/config/FWSystemConfig.ts +4 -4
- package/entry/FWEntry.ts +26 -29
- package/manager/FWAssetManager.ts +46 -67
- package/manager/FWBundleManager.ts +12 -13
- package/manager/FWPromiseManager.ts +39 -76
- package/manager/FWResManager.ts +14 -21
- package/manager/FWUiManager.ts +11 -18
- package/package.json +1 -1
- package/register/FWRegistry.ts +2 -3
- package/service/http/FWHttp.ts +37 -57
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import { FWSystemDefine } from
|
|
2
|
-
import FWLog from
|
|
3
|
-
import { FWManager } from
|
|
4
|
-
|
|
5
|
-
export default class FWPromiseManager
|
|
6
|
-
extends FWManager
|
|
7
|
-
implements FW.PromiseManager
|
|
8
|
-
{
|
|
1
|
+
import { FWSystemDefine } from '../define/FWSystemDefine';
|
|
2
|
+
import FWLog from '../log/FWLog';
|
|
3
|
+
import { FWManager } from './FWManager';
|
|
4
|
+
|
|
5
|
+
export default class FWPromiseManager extends FWManager implements FW.PromiseManager {
|
|
9
6
|
private promiseRegistry: Map<number, FW.PromiseProxy>;
|
|
10
7
|
private uniqueId: number = 0;
|
|
11
8
|
|
|
@@ -21,7 +18,7 @@ export default class FWPromiseManager
|
|
|
21
18
|
/** 创建Promise执行器 */
|
|
22
19
|
public execute<T = any>(
|
|
23
20
|
executor: FW.PromiseExcutor<T>,
|
|
24
|
-
options: FW.PromiseExecuteOptions = {}
|
|
21
|
+
options: FW.PromiseExecuteOptions = {},
|
|
25
22
|
): FW.PromiseProxy<T> {
|
|
26
23
|
const id = this.uniqueId++;
|
|
27
24
|
const abortController = new AbortController();
|
|
@@ -34,18 +31,13 @@ export default class FWPromiseManager
|
|
|
34
31
|
return new Promise<T>((resolve, reject) => {
|
|
35
32
|
if (options.timeout && options.timeout > 0) {
|
|
36
33
|
timerSchedule = FW.Entry.timeMgr.scheduleOnce(() => {
|
|
37
|
-
const timeoutError = new Error(
|
|
38
|
-
`Promise ${id} timeout after ${options.timeout} s`
|
|
39
|
-
);
|
|
34
|
+
const timeoutError = new Error(`Promise ${id} timeout after ${options.timeout} s`);
|
|
40
35
|
if (
|
|
41
36
|
retryCount < maxRetryTimes &&
|
|
42
|
-
(!options.retryCondition ||
|
|
43
|
-
options.retryCondition(timeoutError, retryCount))
|
|
37
|
+
(!options.retryCondition || options.retryCondition(timeoutError, retryCount))
|
|
44
38
|
) {
|
|
45
39
|
retryCount++;
|
|
46
|
-
FWLog.debug(
|
|
47
|
-
`Promise ${id} timeout, retrying (${retryCount}/${maxRetryTimes})`
|
|
48
|
-
);
|
|
40
|
+
FWLog.debug(`Promise ${id} timeout, retrying (${retryCount}/${maxRetryTimes})`);
|
|
49
41
|
if (retryInterval > 0) {
|
|
50
42
|
FW.Entry.timeMgr.scheduleOnce(() => {
|
|
51
43
|
createPromise().then(resolve, reject);
|
|
@@ -61,7 +53,7 @@ export default class FWPromiseManager
|
|
|
61
53
|
}
|
|
62
54
|
|
|
63
55
|
const onAbort = () => {
|
|
64
|
-
FWLog.debug(
|
|
56
|
+
FWLog.debug('promise abort');
|
|
65
57
|
timerSchedule?.unSchedule();
|
|
66
58
|
if (promiseProxy.status === FWSystemDefine.FWPromiseStatus.PENDING) {
|
|
67
59
|
promiseProxy.status = FWSystemDefine.FWPromiseStatus.CANCELLED;
|
|
@@ -74,11 +66,11 @@ export default class FWPromiseManager
|
|
|
74
66
|
return;
|
|
75
67
|
}
|
|
76
68
|
|
|
77
|
-
abortController.signal.addEventListener(
|
|
69
|
+
abortController.signal.addEventListener('abort', onAbort);
|
|
78
70
|
|
|
79
71
|
const wrappedResolve = (value: T | PromiseLike<T>) => {
|
|
80
72
|
promiseProxy.status = FWSystemDefine.FWPromiseStatus.FULFILLED;
|
|
81
|
-
abortController.signal.removeEventListener(
|
|
73
|
+
abortController.signal.removeEventListener('abort', onAbort);
|
|
82
74
|
this.removePromise(id);
|
|
83
75
|
timerSchedule?.unSchedule();
|
|
84
76
|
resolve(value);
|
|
@@ -88,14 +80,10 @@ export default class FWPromiseManager
|
|
|
88
80
|
timerSchedule?.unSchedule();
|
|
89
81
|
if (
|
|
90
82
|
retryCount < maxRetryTimes &&
|
|
91
|
-
(!options.retryCondition ||
|
|
92
|
-
options.retryCondition(reason, retryCount))
|
|
83
|
+
(!options.retryCondition || options.retryCondition(reason, retryCount))
|
|
93
84
|
) {
|
|
94
85
|
retryCount++;
|
|
95
|
-
FWLog.debug(
|
|
96
|
-
`Promise ${id} failed, retrying (${retryCount}/${maxRetryTimes}):`,
|
|
97
|
-
reason
|
|
98
|
-
);
|
|
86
|
+
FWLog.debug(`Promise ${id} failed, retrying (${retryCount}/${maxRetryTimes}):`, reason);
|
|
99
87
|
if (retryInterval > 0) {
|
|
100
88
|
FW.Entry.timeMgr.scheduleOnce(() => {
|
|
101
89
|
createPromise().then(resolve, reject);
|
|
@@ -104,29 +92,18 @@ export default class FWPromiseManager
|
|
|
104
92
|
createPromise().then(resolve, reject);
|
|
105
93
|
}
|
|
106
94
|
} else {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
)
|
|
110
|
-
promiseProxy.status = FWSystemDefine.FWPromiseStatus.REJECTED;
|
|
111
|
-
abortController.signal.removeEventListener("abort", onAbort);
|
|
112
|
-
this.removePromise(id);
|
|
113
|
-
reject(reason);
|
|
114
|
-
}
|
|
95
|
+
abortController.signal.removeEventListener('abort', onAbort);
|
|
96
|
+
this.removePromise(id);
|
|
97
|
+
reject(reason);
|
|
115
98
|
}
|
|
116
99
|
};
|
|
117
100
|
try {
|
|
118
|
-
executor(
|
|
119
|
-
wrappedResolve,
|
|
120
|
-
wrappedReject,
|
|
121
|
-
abortController.signal,
|
|
122
|
-
options.reason
|
|
123
|
-
);
|
|
101
|
+
executor(wrappedResolve, wrappedReject, abortController.signal, options.reason);
|
|
124
102
|
} catch (error) {
|
|
125
103
|
wrappedReject(error);
|
|
126
104
|
}
|
|
127
105
|
});
|
|
128
106
|
};
|
|
129
|
-
|
|
130
107
|
const promise = createPromise();
|
|
131
108
|
const promiseProxy: FW.PromiseProxy<T> = {
|
|
132
109
|
id,
|
|
@@ -135,19 +112,18 @@ export default class FWPromiseManager
|
|
|
135
112
|
abortController,
|
|
136
113
|
abort: (reason?: any) => {
|
|
137
114
|
if (promiseProxy.status === FWSystemDefine.FWPromiseStatus.PENDING) {
|
|
138
|
-
FWLog.debug(reason ||
|
|
115
|
+
FWLog.debug(reason || 'promise cancelled');
|
|
139
116
|
abortController.abort(reason);
|
|
140
117
|
}
|
|
141
118
|
},
|
|
142
119
|
|
|
143
120
|
addAbortEventListener: (
|
|
144
121
|
listener: (this: AbortSignal, ev: Event) => any,
|
|
145
|
-
options?: boolean | AddEventListenerOptions
|
|
122
|
+
options?: boolean | AddEventListenerOptions,
|
|
146
123
|
) => {
|
|
147
|
-
abortController.signal.addEventListener(
|
|
124
|
+
abortController.signal.addEventListener('abort', listener, options);
|
|
148
125
|
},
|
|
149
126
|
};
|
|
150
|
-
|
|
151
127
|
this.promiseRegistry.set(id, promiseProxy);
|
|
152
128
|
return promiseProxy;
|
|
153
129
|
}
|
|
@@ -155,7 +131,7 @@ export default class FWPromiseManager
|
|
|
155
131
|
/** 批量执行Promise并等待所有完成 */
|
|
156
132
|
public all<T = any>(
|
|
157
133
|
promises: FW.PromiseProxy<T>[],
|
|
158
|
-
options: FW.PromiseExecuteOptions = {}
|
|
134
|
+
options: FW.PromiseExecuteOptions = {},
|
|
159
135
|
): FW.PromiseProxy<FW.PromiseResult<T>> {
|
|
160
136
|
const id = this.uniqueId++;
|
|
161
137
|
const abortController = new AbortController();
|
|
@@ -169,18 +145,13 @@ export default class FWPromiseManager
|
|
|
169
145
|
if (options.timeout && options.timeout > 0) {
|
|
170
146
|
timerSchedule?.unSchedule();
|
|
171
147
|
timerSchedule = FW.Entry.timeMgr.scheduleOnce(() => {
|
|
172
|
-
const timeoutError = new Error(
|
|
173
|
-
`All Promise ${id} timeout after ${options.timeout} s`
|
|
174
|
-
);
|
|
148
|
+
const timeoutError = new Error(`All Promise ${id} timeout after ${options.timeout} s`);
|
|
175
149
|
if (
|
|
176
150
|
retryCount < maxRetryTimes &&
|
|
177
|
-
(!options.retryCondition ||
|
|
178
|
-
options.retryCondition(timeoutError, retryCount))
|
|
151
|
+
(!options.retryCondition || options.retryCondition(timeoutError, retryCount))
|
|
179
152
|
) {
|
|
180
153
|
retryCount++;
|
|
181
|
-
FWLog.debug(
|
|
182
|
-
`All Promise ${id} timeout, retrying (${retryCount}/${maxRetryTimes})`
|
|
183
|
-
);
|
|
154
|
+
FWLog.debug(`All Promise ${id} timeout, retrying (${retryCount}/${maxRetryTimes})`);
|
|
184
155
|
if (retryInterval > 0) {
|
|
185
156
|
FW.Entry.timeMgr.scheduleOnce(() => {
|
|
186
157
|
createPromise().then(resolve, reject);
|
|
@@ -208,7 +179,7 @@ export default class FWPromiseManager
|
|
|
208
179
|
return;
|
|
209
180
|
}
|
|
210
181
|
|
|
211
|
-
abortController.signal.addEventListener(
|
|
182
|
+
abortController.signal.addEventListener('abort', onAbort);
|
|
212
183
|
|
|
213
184
|
const processAll = async () => {
|
|
214
185
|
const result: FW.PromiseResult<T> = {
|
|
@@ -225,8 +196,8 @@ export default class FWPromiseManager
|
|
|
225
196
|
.filter(
|
|
226
197
|
(id) =>
|
|
227
198
|
!result.success.some((s) => s.id === id) &&
|
|
228
|
-
!result.failed.some((f) => f.id === id)
|
|
229
|
-
)
|
|
199
|
+
!result.failed.some((f) => f.id === id),
|
|
200
|
+
),
|
|
230
201
|
);
|
|
231
202
|
break;
|
|
232
203
|
}
|
|
@@ -235,9 +206,7 @@ export default class FWPromiseManager
|
|
|
235
206
|
const value = await promiseProxy.promise;
|
|
236
207
|
result.success.push(value);
|
|
237
208
|
} catch (error) {
|
|
238
|
-
if (
|
|
239
|
-
promiseProxy.status === FWSystemDefine.FWPromiseStatus.CANCELLED
|
|
240
|
-
) {
|
|
209
|
+
if (promiseProxy.status === FWSystemDefine.FWPromiseStatus.CANCELLED) {
|
|
241
210
|
result.cancelled.push(promiseProxy.id);
|
|
242
211
|
} else {
|
|
243
212
|
result.failed.push({
|
|
@@ -254,7 +223,7 @@ export default class FWPromiseManager
|
|
|
254
223
|
processAll()
|
|
255
224
|
.then((result) => {
|
|
256
225
|
promiseProxy.status = FWSystemDefine.FWPromiseStatus.FULFILLED;
|
|
257
|
-
abortController.signal.removeEventListener(
|
|
226
|
+
abortController.signal.removeEventListener('abort', onAbort);
|
|
258
227
|
this.removePromise(id);
|
|
259
228
|
timerSchedule?.unSchedule();
|
|
260
229
|
resolve(result);
|
|
@@ -263,13 +232,12 @@ export default class FWPromiseManager
|
|
|
263
232
|
timerSchedule?.unSchedule();
|
|
264
233
|
if (
|
|
265
234
|
retryCount < maxRetryTimes &&
|
|
266
|
-
(!options.retryCondition ||
|
|
267
|
-
options.retryCondition(error, retryCount))
|
|
235
|
+
(!options.retryCondition || options.retryCondition(error, retryCount))
|
|
268
236
|
) {
|
|
269
237
|
retryCount++;
|
|
270
238
|
FWLog.debug(
|
|
271
239
|
`All Promise ${id} failed, retrying (${retryCount}/${maxRetryTimes}):`,
|
|
272
|
-
error
|
|
240
|
+
error,
|
|
273
241
|
);
|
|
274
242
|
if (retryInterval > 0) {
|
|
275
243
|
FW.Entry.timeMgr.scheduleOnce(() => {
|
|
@@ -279,11 +247,9 @@ export default class FWPromiseManager
|
|
|
279
247
|
createPromise().then(resolve, reject);
|
|
280
248
|
}
|
|
281
249
|
} else {
|
|
282
|
-
if (
|
|
283
|
-
promiseProxy.status === FWSystemDefine.FWPromiseStatus.PENDING
|
|
284
|
-
) {
|
|
250
|
+
if (promiseProxy.status === FWSystemDefine.FWPromiseStatus.PENDING) {
|
|
285
251
|
promiseProxy.status = FWSystemDefine.FWPromiseStatus.REJECTED;
|
|
286
|
-
abortController.signal.removeEventListener(
|
|
252
|
+
abortController.signal.removeEventListener('abort', onAbort);
|
|
287
253
|
this.removePromise(id);
|
|
288
254
|
reject(error);
|
|
289
255
|
}
|
|
@@ -300,15 +266,15 @@ export default class FWPromiseManager
|
|
|
300
266
|
abortController,
|
|
301
267
|
abort: (reason?: any) => {
|
|
302
268
|
if (promiseProxy.status === FWSystemDefine.FWPromiseStatus.PENDING) {
|
|
303
|
-
FWLog.debug(reason ||
|
|
269
|
+
FWLog.debug(reason || 'all promise cancelled');
|
|
304
270
|
abortController.abort(reason);
|
|
305
271
|
}
|
|
306
272
|
},
|
|
307
273
|
addAbortEventListener: (
|
|
308
274
|
listener: (this: AbortSignal, ev: Event) => any,
|
|
309
|
-
options?: boolean | AddEventListenerOptions
|
|
275
|
+
options?: boolean | AddEventListenerOptions,
|
|
310
276
|
) => {
|
|
311
|
-
abortController.signal.addEventListener(
|
|
277
|
+
abortController.signal.addEventListener('abort', listener, options);
|
|
312
278
|
},
|
|
313
279
|
};
|
|
314
280
|
|
|
@@ -319,10 +285,7 @@ export default class FWPromiseManager
|
|
|
319
285
|
/** 取消指定Promise */
|
|
320
286
|
public cancel(id: number, reason?: any): boolean {
|
|
321
287
|
const promiseProxy = this.promiseRegistry.get(id);
|
|
322
|
-
if (
|
|
323
|
-
promiseProxy &&
|
|
324
|
-
promiseProxy.status === FWSystemDefine.FWPromiseStatus.PENDING
|
|
325
|
-
) {
|
|
288
|
+
if (promiseProxy && promiseProxy.status === FWSystemDefine.FWPromiseStatus.PENDING) {
|
|
326
289
|
promiseProxy.abort(reason);
|
|
327
290
|
return true;
|
|
328
291
|
}
|
|
@@ -373,7 +336,7 @@ export default class FWPromiseManager
|
|
|
373
336
|
/** 获取正在执行的Promise数量 */
|
|
374
337
|
public getActiveCount(): number {
|
|
375
338
|
return Array.from(this.promiseRegistry.values()).filter(
|
|
376
|
-
(p) => p.status === FWSystemDefine.FWPromiseStatus.PENDING
|
|
339
|
+
(p) => p.status === FWSystemDefine.FWPromiseStatus.PENDING,
|
|
377
340
|
).length;
|
|
378
341
|
}
|
|
379
342
|
|
package/manager/FWResManager.ts
CHANGED
|
@@ -1,21 +1,19 @@
|
|
|
1
|
-
import FWAssetConfig from
|
|
2
|
-
import { FWSystemConfig } from
|
|
3
|
-
import { FWSystemDefine } from
|
|
4
|
-
import FWLog from
|
|
5
|
-
import { FWLodash } from
|
|
6
|
-
import { FWAssetManager } from
|
|
7
|
-
import { FWBundleManager } from
|
|
8
|
-
import { FWManager } from
|
|
1
|
+
import FWAssetConfig from '../config/FWAssetConfig';
|
|
2
|
+
import { FWSystemConfig } from '../config/FWSystemConfig';
|
|
3
|
+
import { FWSystemDefine } from '../define/FWSystemDefine';
|
|
4
|
+
import FWLog from '../log/FWLog';
|
|
5
|
+
import { FWLodash } from '../utils/FWLodash';
|
|
6
|
+
import { FWAssetManager } from './FWAssetManager';
|
|
7
|
+
import { FWBundleManager } from './FWBundleManager';
|
|
8
|
+
import { FWManager } from './FWManager';
|
|
9
9
|
|
|
10
10
|
export class FWResManager extends FWManager implements FW.ResManager {
|
|
11
|
-
bundleMgr: FW.BundleManager;
|
|
12
|
-
assetMgr: FW.AssetManager;
|
|
11
|
+
private bundleMgr: FW.BundleManager;
|
|
12
|
+
private assetMgr: FW.AssetManager;
|
|
13
13
|
|
|
14
14
|
public initialize() {
|
|
15
15
|
this.bundleMgr = new FWBundleManager(this);
|
|
16
16
|
this.assetMgr = new FWAssetManager(this);
|
|
17
|
-
this.bundleMgr.initialize();
|
|
18
|
-
this.assetMgr.initialize();
|
|
19
17
|
}
|
|
20
18
|
|
|
21
19
|
/**
|
|
@@ -36,7 +34,7 @@ export class FWResManager extends FWManager implements FW.ResManager {
|
|
|
36
34
|
await this.loadBundle(depend);
|
|
37
35
|
|
|
38
36
|
const config = FW.Entry.getComponent<FWAssetConfig>(
|
|
39
|
-
`${depend}${FWSystemDefine.FWBindTag.CONFIG}
|
|
37
|
+
`${depend}${FWSystemDefine.FWBindTag.CONFIG}`,
|
|
40
38
|
);
|
|
41
39
|
if (!config) continue;
|
|
42
40
|
const preLoad = config.preLoad;
|
|
@@ -72,7 +70,7 @@ export class FWResManager extends FWManager implements FW.ResManager {
|
|
|
72
70
|
reject(e);
|
|
73
71
|
}
|
|
74
72
|
}, FWSystemConfig.PromiseConfig.loadBundle).promise,
|
|
75
|
-
`
|
|
73
|
+
`loadBundle -> ${bundleName}`,
|
|
76
74
|
);
|
|
77
75
|
}
|
|
78
76
|
/**
|
|
@@ -89,10 +87,7 @@ export class FWResManager extends FWManager implements FW.ResManager {
|
|
|
89
87
|
return await this.assetMgr.loadSpineDataFromRemote(data);
|
|
90
88
|
}
|
|
91
89
|
|
|
92
|
-
async loadRemote<T extends cc.Asset = cc.Asset>(
|
|
93
|
-
url: string,
|
|
94
|
-
cb: (asset: any) => T
|
|
95
|
-
): Promise<T> {
|
|
90
|
+
async loadRemote<T extends cc.Asset = cc.Asset>(url: string, cb: (asset: any) => T): Promise<T> {
|
|
96
91
|
const asset = await this.assetMgr.loadRemote(url);
|
|
97
92
|
if (asset instanceof cc.Texture2D) {
|
|
98
93
|
return new cc.SpriteFrame(asset) as unknown as T;
|
|
@@ -139,9 +134,7 @@ export class FWResManager extends FWManager implements FW.ResManager {
|
|
|
139
134
|
* @param assetProperty
|
|
140
135
|
* @returns
|
|
141
136
|
*/
|
|
142
|
-
async loadAsset<T extends cc.Asset>(
|
|
143
|
-
assetProperty: FW.AssetProperty
|
|
144
|
-
): Promise<T> {
|
|
137
|
+
async loadAsset<T extends cc.Asset>(assetProperty: FW.AssetProperty): Promise<T> {
|
|
145
138
|
const res = await this.assetMgr.load(assetProperty);
|
|
146
139
|
return this.process<T>(res).asset as T;
|
|
147
140
|
}
|
package/manager/FWUiManager.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { searchChild } from
|
|
2
|
-
import FWLog from
|
|
3
|
-
import { FWManager } from
|
|
1
|
+
import { searchChild } from '../expand/FWDecorator';
|
|
2
|
+
import FWLog from '../log/FWLog';
|
|
3
|
+
import { FWManager } from './FWManager';
|
|
4
4
|
|
|
5
5
|
export default class FWUiManager extends FWManager implements FW.UiManager {
|
|
6
6
|
private eventMap: Map<
|
|
@@ -113,7 +113,7 @@ export default class FWUiManager extends FWManager implements FW.UiManager {
|
|
|
113
113
|
|
|
114
114
|
register(args: FW.RegisterArgs) {
|
|
115
115
|
if (!args.target) {
|
|
116
|
-
FWLog.error(
|
|
116
|
+
FWLog.error('注册事件失败,目标为空!');
|
|
117
117
|
return;
|
|
118
118
|
}
|
|
119
119
|
|
|
@@ -131,11 +131,7 @@ export default class FWUiManager extends FWManager implements FW.UiManager {
|
|
|
131
131
|
|
|
132
132
|
if (!evt.enable) return;
|
|
133
133
|
|
|
134
|
-
|
|
135
|
-
if (
|
|
136
|
-
Date.now() - evt.lastResponseTimestamp <
|
|
137
|
-
evt.responseInterval
|
|
138
|
-
) {
|
|
134
|
+
if (Date.now() - evt.lastResponseTimestamp < evt.responseInterval) {
|
|
139
135
|
return;
|
|
140
136
|
}
|
|
141
137
|
|
|
@@ -143,9 +139,9 @@ export default class FWUiManager extends FWManager implements FW.UiManager {
|
|
|
143
139
|
if (button && !button.interactable) return;
|
|
144
140
|
|
|
145
141
|
evt.lastResponseTimestamp = Date.now();
|
|
146
|
-
evt.cb?.bind(args.target)?.(e, c);
|
|
142
|
+
evt.cb?.bind(args.target)?.(e, c, evt.data);
|
|
147
143
|
},
|
|
148
|
-
args.target
|
|
144
|
+
args.target,
|
|
149
145
|
);
|
|
150
146
|
this.eventMap.set(this.uniqueId, {
|
|
151
147
|
uniqueId: this.uniqueId,
|
|
@@ -168,12 +164,9 @@ export default class FWUiManager extends FWManager implements FW.UiManager {
|
|
|
168
164
|
args7?: FW.EventManagerArgs,
|
|
169
165
|
args8?: FW.EventManagerArgs,
|
|
170
166
|
args9?: FW.EventManagerArgs,
|
|
171
|
-
args10?: FW.EventManagerArgs
|
|
167
|
+
args10?: FW.EventManagerArgs,
|
|
172
168
|
) => {
|
|
173
|
-
if (
|
|
174
|
-
Date.now() - evt.lastResponseTimestamp <
|
|
175
|
-
(evt.responseInterval || 0)
|
|
176
|
-
) {
|
|
169
|
+
if (Date.now() - evt.lastResponseTimestamp < (evt.responseInterval || 0)) {
|
|
177
170
|
return;
|
|
178
171
|
}
|
|
179
172
|
evt.lastResponseTimestamp = Date.now();
|
|
@@ -187,10 +180,10 @@ export default class FWUiManager extends FWManager implements FW.UiManager {
|
|
|
187
180
|
args7,
|
|
188
181
|
args8,
|
|
189
182
|
args9,
|
|
190
|
-
args10
|
|
183
|
+
args10,
|
|
191
184
|
);
|
|
192
185
|
},
|
|
193
|
-
args.target
|
|
186
|
+
args.target,
|
|
194
187
|
);
|
|
195
188
|
|
|
196
189
|
this.eventMap.set(this.uniqueId, {
|
package/package.json
CHANGED
package/register/FWRegistry.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { injectable } from 'inversify';
|
|
2
|
-
import Framework from '../Framework';
|
|
3
2
|
|
|
4
3
|
@injectable()
|
|
5
4
|
export default abstract class FWRegistry implements FW.Registry {
|
|
@@ -48,9 +47,9 @@ export default abstract class FWRegistry implements FW.Registry {
|
|
|
48
47
|
}
|
|
49
48
|
|
|
50
49
|
private bundleEnabled(enable?: boolean) {
|
|
51
|
-
const frameworkInvoke = enable ? Framework.register : Framework.unRegister;
|
|
50
|
+
const frameworkInvoke = enable ? FW.Framework.register : FW.Framework.unRegister;
|
|
52
51
|
const entryInvoke = enable ? FW.Entry.register : FW.Entry.unRegister;
|
|
53
|
-
frameworkInvoke.bind(Framework)({
|
|
52
|
+
frameworkInvoke.bind(FW.Framework)({
|
|
54
53
|
bundleName: this.bundleName,
|
|
55
54
|
logic: this.logic,
|
|
56
55
|
data: this.data,
|
package/service/http/FWHttp.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { FWSystemConfig } from
|
|
2
|
-
import { FWSystemDefine } from
|
|
3
|
-
import FWLog from
|
|
4
|
-
import FWService from
|
|
1
|
+
import { FWSystemConfig } from '../../config/FWSystemConfig';
|
|
2
|
+
import { FWSystemDefine } from '../../define/FWSystemDefine';
|
|
3
|
+
import FWLog from '../../log/FWLog';
|
|
4
|
+
import FWService from '../FWService';
|
|
5
5
|
|
|
6
6
|
export default class FWHttp extends FWService {
|
|
7
7
|
public initialize() {}
|
|
@@ -12,30 +12,18 @@ export default class FWHttp extends FWService {
|
|
|
12
12
|
url: string,
|
|
13
13
|
params?: string,
|
|
14
14
|
cb?: (response: string) => void,
|
|
15
|
-
tag?: string
|
|
15
|
+
tag?: string,
|
|
16
16
|
): Promise<string> {
|
|
17
|
-
return this.process(
|
|
18
|
-
url,
|
|
19
|
-
params,
|
|
20
|
-
cb,
|
|
21
|
-
tag,
|
|
22
|
-
FWSystemDefine.FWHttpRequestType.GET
|
|
23
|
-
);
|
|
17
|
+
return this.process(url, params, cb, tag, FWSystemDefine.FWHttpRequestType.GET);
|
|
24
18
|
}
|
|
25
19
|
|
|
26
20
|
protected async postMessage(
|
|
27
21
|
url: string,
|
|
28
22
|
params?: string,
|
|
29
23
|
cb?: (response: string) => void,
|
|
30
|
-
tag?: string
|
|
24
|
+
tag?: string,
|
|
31
25
|
): Promise<string> {
|
|
32
|
-
return this.process(
|
|
33
|
-
url,
|
|
34
|
-
params,
|
|
35
|
-
cb,
|
|
36
|
-
tag,
|
|
37
|
-
FWSystemDefine.FWHttpRequestType.POST
|
|
38
|
-
);
|
|
26
|
+
return this.process(url, params, cb, tag, FWSystemDefine.FWHttpRequestType.POST);
|
|
39
27
|
}
|
|
40
28
|
|
|
41
29
|
private async process(
|
|
@@ -43,56 +31,48 @@ export default class FWHttp extends FWService {
|
|
|
43
31
|
params: string,
|
|
44
32
|
cb: (response: any) => void,
|
|
45
33
|
tag: string,
|
|
46
|
-
type: FWSystemDefine.FWHttpRequestType
|
|
34
|
+
type: FWSystemDefine.FWHttpRequestType,
|
|
47
35
|
): Promise<string> {
|
|
48
36
|
let xhr: XMLHttpRequest;
|
|
49
37
|
|
|
50
|
-
const promiseProxy: FW.PromiseProxy<string> =
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
xhr = new XMLHttpRequest();
|
|
38
|
+
const promiseProxy: FW.PromiseProxy<string> = FW.Entry.promiseMgr.execute<string>(
|
|
39
|
+
(resolve, reject, signal, reason) => {
|
|
40
|
+
xhr = new XMLHttpRequest();
|
|
54
41
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
42
|
+
xhr.onreadystatechange = () => {
|
|
43
|
+
if (xhr.readyState == 4 && xhr.status === 200) {
|
|
44
|
+
cb?.(xhr.response);
|
|
45
|
+
resolve(xhr.response);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
61
48
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
49
|
+
xhr.onerror = (err: any) => {
|
|
50
|
+
FWLog.error(err);
|
|
51
|
+
this.onError?.(err);
|
|
52
|
+
reject(`http request error:${err}`);
|
|
53
|
+
};
|
|
67
54
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
55
|
+
xhr.ontimeout = () => {
|
|
56
|
+
this.onTimeout?.();
|
|
57
|
+
reject(`http request timeout!`);
|
|
58
|
+
};
|
|
72
59
|
|
|
73
|
-
|
|
74
|
-
|
|
60
|
+
xhr.open(type, url, true);
|
|
61
|
+
xhr.send(params);
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
...FWSystemConfig.PromiseConfig.http,
|
|
65
|
+
retryCondition(error, retryCount) {
|
|
66
|
+
return error || xhr.readyState != 4 || (xhr.status !== 200 && retryCount < 3);
|
|
75
67
|
},
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
retryCondition(error, retryCount) {
|
|
79
|
-
return (
|
|
80
|
-
error ||
|
|
81
|
-
xhr.readyState != 4 ||
|
|
82
|
-
(xhr.status !== 200 && retryCount < 3)
|
|
83
|
-
);
|
|
84
|
-
},
|
|
85
|
-
}
|
|
86
|
-
);
|
|
68
|
+
},
|
|
69
|
+
);
|
|
87
70
|
|
|
88
71
|
promiseProxy.addAbortEventListener(() => {
|
|
89
72
|
xhr.abort();
|
|
90
73
|
});
|
|
91
74
|
|
|
92
|
-
return await this.invoke(
|
|
93
|
-
promiseProxy.promise,
|
|
94
|
-
tag ? `http request ->${tag}` : ""
|
|
95
|
-
);
|
|
75
|
+
return await this.invoke(promiseProxy.promise, tag ? `http request ->${tag}` : '');
|
|
96
76
|
}
|
|
97
77
|
|
|
98
78
|
onError?(err: any);
|