@ives_xxz/framework 1.5.5 → 1.5.8
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 +129 -56
- package/Framework.ts +64 -24
- package/FrameworkBase.ts +58 -26
- package/controller/FWLayerController.ts +17 -12
- package/data/FWData.ts +3 -5
- package/logic/FWLogic.ts +4 -6
- package/manager/FWLayerManager.ts +124 -69
- package/manager/FWPromiseManager.ts +69 -38
- package/manager/FWTaskManager.ts +2 -2
- package/package.json +4 -2
- package/service/FWService.ts +2 -4
- package/service/socket/FWSocket.ts +44 -33
- package/service/socket/FWSocketHandle.ts +14 -14
- package/service/socket/FWSocketSender.ts +11 -12
package/FW.d.ts
CHANGED
|
@@ -6,13 +6,18 @@ declare namespace FW {
|
|
|
6
6
|
prototype: T;
|
|
7
7
|
};
|
|
8
8
|
|
|
9
|
-
type ServiceIdentifierData<TInstance = unknown> =
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
TInstance
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
type
|
|
9
|
+
type ServiceIdentifierData<TInstance = unknown> =
|
|
10
|
+
| string
|
|
11
|
+
| symbol
|
|
12
|
+
| Newable<TInstance>
|
|
13
|
+
| Function;
|
|
14
|
+
|
|
15
|
+
type CommonNewable<
|
|
16
|
+
TInstance = unknown,
|
|
17
|
+
TArgs extends unknown[] = any[]
|
|
18
|
+
> = Newable<TInstance, TArgs>;
|
|
19
|
+
type CommonServiceIdentifier<TInstance = unknown> =
|
|
20
|
+
ServiceIdentifierData<TInstance>;
|
|
16
21
|
|
|
17
22
|
type ServiceIdentifier<T = unknown> = CommonServiceIdentifier<T>;
|
|
18
23
|
/**
|
|
@@ -58,13 +63,13 @@ declare namespace FW {
|
|
|
58
63
|
resolve: (value: T | PromiseLike<T>) => void,
|
|
59
64
|
reject: (reason?: any) => void,
|
|
60
65
|
signal?: AbortSignal,
|
|
61
|
-
reason?: any
|
|
66
|
+
reason?: any
|
|
62
67
|
) => void = PromiseExcutor,
|
|
63
|
-
options: PromiseExecuteOptions = {}
|
|
68
|
+
options: PromiseExecuteOptions = {}
|
|
64
69
|
): PromiseProxy<T>;
|
|
65
70
|
all<T = any>(
|
|
66
71
|
promises: FW.PromiseProxy<T>[],
|
|
67
|
-
options: FW.PromiseExecuteOptions = {}
|
|
72
|
+
options: FW.PromiseExecuteOptions = {}
|
|
68
73
|
): FW.PromiseProxy<FW.PromiseResult<T>>;
|
|
69
74
|
};
|
|
70
75
|
|
|
@@ -79,18 +84,22 @@ declare namespace FW {
|
|
|
79
84
|
registerLanguagePackageEnum(
|
|
80
85
|
bundleName: string,
|
|
81
86
|
language: any,
|
|
82
|
-
getter: (key: string, language?: string) => string
|
|
87
|
+
getter: (key: string, language?: string) => string
|
|
83
88
|
): void;
|
|
84
89
|
getSupportedLanguages(): string[];
|
|
85
90
|
setSupportedLanguages(languages: string[]): void;
|
|
86
91
|
getBundles(): string[];
|
|
87
92
|
getLanguage(): string;
|
|
88
93
|
getLanguageIndex(): number;
|
|
89
|
-
getLanguagePackageValue(
|
|
94
|
+
getLanguagePackageValue(
|
|
95
|
+
bundleName: string,
|
|
96
|
+
key: string,
|
|
97
|
+
language?: string
|
|
98
|
+
): string;
|
|
90
99
|
getLanguagePackageEnumKeys(bundleName: string): string[];
|
|
91
100
|
getLanguagePackageEnumValues(bundleName: string): string[];
|
|
92
101
|
getLanguagePackageEnum<K extends keyof ILanguageBundleAccessor>(
|
|
93
|
-
bundleName: K
|
|
102
|
+
bundleName: K
|
|
94
103
|
): ILanguageBundleAccessor[K];
|
|
95
104
|
initializeLanguage(language: string);
|
|
96
105
|
};
|
|
@@ -119,6 +128,7 @@ declare namespace FW {
|
|
|
119
128
|
onBeforeSendingMessage?(msg: any): Promise<FW.SocketMessage>;
|
|
120
129
|
/** 是否是心跳消息 */
|
|
121
130
|
onHeart?(msg: any): Promise<boolean>;
|
|
131
|
+
sendHeart(): void;
|
|
122
132
|
};
|
|
123
133
|
type SocketHandle = {
|
|
124
134
|
readonly entry: FW.Entry;
|
|
@@ -149,32 +159,32 @@ declare namespace FW {
|
|
|
149
159
|
createObjectPool<T extends FWObject = FWObject>(
|
|
150
160
|
node: cc.Node,
|
|
151
161
|
parent: cc.Node,
|
|
152
|
-
tag?: string
|
|
162
|
+
tag?: string
|
|
153
163
|
): Promise<ObjectPool<T>>;
|
|
154
164
|
createObjectPool<T extends FWObject = FWObject>(
|
|
155
165
|
prefab: cc.Prefab,
|
|
156
166
|
parent: cc.Node,
|
|
157
|
-
tag?: string
|
|
167
|
+
tag?: string
|
|
158
168
|
): Promise<ObjectPool<T>>;
|
|
159
169
|
createObjectPool<T extends FWObject = FWObject>(
|
|
160
170
|
assetProperty: FW.AssetProperty,
|
|
161
171
|
parent: cc.Node,
|
|
162
|
-
tag?: string
|
|
172
|
+
tag?: string
|
|
163
173
|
): Promise<ObjectPool<T>>;
|
|
164
174
|
createObjectPool<T extends FWObject = FWObject>(
|
|
165
175
|
node: cc.Node,
|
|
166
176
|
parent: cc.Node,
|
|
167
|
-
type?: number
|
|
177
|
+
type?: number
|
|
168
178
|
): Promise<ObjectPool<T>>;
|
|
169
179
|
createObjectPool<T extends FWObject = FWObject>(
|
|
170
180
|
prefab: cc.Prefab,
|
|
171
181
|
parent: cc.Node,
|
|
172
|
-
type?: number
|
|
182
|
+
type?: number
|
|
173
183
|
): Promise<ObjectPool<T>>;
|
|
174
184
|
createObjectPool<T extends FWObject = FWObject>(
|
|
175
185
|
assetProperty: FW.AssetProperty,
|
|
176
186
|
parent: cc.Node,
|
|
177
|
-
type?: number
|
|
187
|
+
type?: number
|
|
178
188
|
): Promise<ObjectPool<T>>;
|
|
179
189
|
/** 获取已经创建的对象池 */
|
|
180
190
|
getObjectPool(tag: string): ObjectPool;
|
|
@@ -207,7 +217,7 @@ declare namespace FW {
|
|
|
207
217
|
address: string,
|
|
208
218
|
sender: SocketSender,
|
|
209
219
|
handle: SocketHandle,
|
|
210
|
-
config: SocketConfig
|
|
220
|
+
config: SocketConfig
|
|
211
221
|
): Promise<Socket>;
|
|
212
222
|
/**
|
|
213
223
|
* 获取socket
|
|
@@ -303,7 +313,7 @@ declare namespace FW {
|
|
|
303
313
|
tag: string,
|
|
304
314
|
sender: SocketSender,
|
|
305
315
|
handle: SocketHandle,
|
|
306
|
-
config: SocketConfig
|
|
316
|
+
config: SocketConfig
|
|
307
317
|
): SocketPromiseProxy;
|
|
308
318
|
};
|
|
309
319
|
|
|
@@ -338,7 +348,7 @@ declare namespace FW {
|
|
|
338
348
|
args7?: FW.EventManagerArgs,
|
|
339
349
|
args8?: FW.EventManagerArgs,
|
|
340
350
|
args9?: FW.EventManagerArgs,
|
|
341
|
-
args10?: FW.EventManagerArgs
|
|
351
|
+
args10?: FW.EventManagerArgs
|
|
342
352
|
);
|
|
343
353
|
/**
|
|
344
354
|
* 比较目标
|
|
@@ -398,19 +408,35 @@ declare namespace FW {
|
|
|
398
408
|
/**
|
|
399
409
|
* 一次性调度器
|
|
400
410
|
*/
|
|
401
|
-
scheduleOnce(
|
|
411
|
+
scheduleOnce(
|
|
412
|
+
cb?: () => void,
|
|
413
|
+
time?: number,
|
|
414
|
+
tag?: string
|
|
415
|
+
): FW.TimerSchedule;
|
|
402
416
|
/**
|
|
403
417
|
* 一次性调度器
|
|
404
418
|
*/
|
|
405
|
-
scheduleOnce(
|
|
419
|
+
scheduleOnce(
|
|
420
|
+
time?: number,
|
|
421
|
+
cb?: () => void,
|
|
422
|
+
tag?: string
|
|
423
|
+
): FW.TimerSchedule;
|
|
406
424
|
/**
|
|
407
425
|
* 一次性调度器
|
|
408
426
|
*/
|
|
409
|
-
scheduleOnce(
|
|
427
|
+
scheduleOnce(
|
|
428
|
+
time?: number,
|
|
429
|
+
cb?: () => void,
|
|
430
|
+
target?: any
|
|
431
|
+
): FW.TimerSchedule;
|
|
410
432
|
/**
|
|
411
433
|
* 一次性调度器
|
|
412
434
|
*/
|
|
413
|
-
scheduleOnce(
|
|
435
|
+
scheduleOnce(
|
|
436
|
+
cb?: () => void,
|
|
437
|
+
time?: number,
|
|
438
|
+
target?: any
|
|
439
|
+
): FW.TimerSchedule;
|
|
414
440
|
/**
|
|
415
441
|
* 自定义调度器
|
|
416
442
|
* */
|
|
@@ -419,7 +445,7 @@ declare namespace FW {
|
|
|
419
445
|
time?: number,
|
|
420
446
|
repeat?: number,
|
|
421
447
|
target?: TargetType,
|
|
422
|
-
tag?: string
|
|
448
|
+
tag?: string
|
|
423
449
|
): TimerSchedule;
|
|
424
450
|
/** 暂停调度器 */
|
|
425
451
|
pauseSchedule(tag: string): void;
|
|
@@ -470,13 +496,13 @@ declare namespace FW {
|
|
|
470
496
|
args7?: EventManagerArgs,
|
|
471
497
|
args8?: EventManagerArgs,
|
|
472
498
|
args9?: EventManagerArgs,
|
|
473
|
-
args10?: EventManagerArgs
|
|
499
|
+
args10?: EventManagerArgs
|
|
474
500
|
) => void,
|
|
475
501
|
target: TargetType,
|
|
476
502
|
options?: {
|
|
477
503
|
priority?: FWSystemDefine.FWPriorityOrder;
|
|
478
504
|
intercept?: boolean;
|
|
479
|
-
}
|
|
505
|
+
}
|
|
480
506
|
);
|
|
481
507
|
|
|
482
508
|
registerOnce(
|
|
@@ -491,13 +517,13 @@ declare namespace FW {
|
|
|
491
517
|
args7?: EventManagerArgs,
|
|
492
518
|
args8?: EventManagerArgs,
|
|
493
519
|
args9?: EventManagerArgs,
|
|
494
|
-
args10?: EventManagerArgs
|
|
520
|
+
args10?: EventManagerArgs
|
|
495
521
|
) => void,
|
|
496
522
|
target: TargetType,
|
|
497
523
|
options?: {
|
|
498
524
|
priority?: number;
|
|
499
525
|
intercept?: boolean;
|
|
500
|
-
}
|
|
526
|
+
}
|
|
501
527
|
): void;
|
|
502
528
|
|
|
503
529
|
/**
|
|
@@ -531,7 +557,7 @@ declare namespace FW {
|
|
|
531
557
|
args7?: FW.EventManagerArgs,
|
|
532
558
|
args8?: FW.EventManagerArgs,
|
|
533
559
|
args9?: FW.EventManagerArgs,
|
|
534
|
-
args10?: FW.EventManagerArgs
|
|
560
|
+
args10?: FW.EventManagerArgs
|
|
535
561
|
): void;
|
|
536
562
|
/**
|
|
537
563
|
* 注销事件
|
|
@@ -677,19 +703,23 @@ declare namespace FW {
|
|
|
677
703
|
* @param data
|
|
678
704
|
*/
|
|
679
705
|
openAsync<Ctr extends FWLayerController = FWLayerController>(
|
|
680
|
-
data: LayerOpenArgs<Ctr
|
|
706
|
+
data: LayerOpenArgs<Ctr>
|
|
681
707
|
): Promise<Ctr>;
|
|
682
708
|
|
|
683
709
|
/**
|
|
684
710
|
* 同步打开layer
|
|
685
711
|
* @param data
|
|
686
712
|
*/
|
|
687
|
-
openSync<Ctr extends FWLayerController = FWLayerController>(
|
|
713
|
+
openSync<Ctr extends FWLayerController = FWLayerController>(
|
|
714
|
+
data: LayerOpenArgs<Ctr>
|
|
715
|
+
): Ctr;
|
|
688
716
|
/**
|
|
689
717
|
* 显示常驻layer
|
|
690
718
|
* @param layer
|
|
691
719
|
*/
|
|
692
|
-
displayLayer<Ctr extends FWLayerController = FWLayerController>(
|
|
720
|
+
displayLayer<Ctr extends FWLayerController = FWLayerController>(
|
|
721
|
+
ctr: Ctr
|
|
722
|
+
): Ctr;
|
|
693
723
|
/**
|
|
694
724
|
* 隐藏常驻layer
|
|
695
725
|
* @param layer
|
|
@@ -699,7 +729,9 @@ declare namespace FW {
|
|
|
699
729
|
* 关闭layer
|
|
700
730
|
* @param layer
|
|
701
731
|
*/
|
|
702
|
-
close<Ctr extends FWLayerController = FWLayerController>(
|
|
732
|
+
close<Ctr extends FWLayerController = FWLayerController>(
|
|
733
|
+
ctr: Ctr
|
|
734
|
+
): FWLayerController;
|
|
703
735
|
|
|
704
736
|
/**
|
|
705
737
|
* 从栈关闭
|
|
@@ -802,7 +834,10 @@ declare namespace FW {
|
|
|
802
834
|
* @param url
|
|
803
835
|
* @param cb
|
|
804
836
|
*/
|
|
805
|
-
loadRemote<T extends cc.Asset = cc.Asset>(
|
|
837
|
+
loadRemote<T extends cc.Asset = cc.Asset>(
|
|
838
|
+
url: string,
|
|
839
|
+
cb?: (asset: cc.Asset) => T
|
|
840
|
+
): Promise<T>;
|
|
806
841
|
/**
|
|
807
842
|
* 从远程加载spine动画
|
|
808
843
|
* @param data
|
|
@@ -818,13 +853,18 @@ declare namespace FW {
|
|
|
818
853
|
* 加载资源返回数据
|
|
819
854
|
* @param assetProperty
|
|
820
855
|
*/
|
|
821
|
-
loadAssetData<T extends cc.Asset>(
|
|
856
|
+
loadAssetData<T extends cc.Asset>(
|
|
857
|
+
assetProperty: AssetProperty
|
|
858
|
+
): Promise<AssetData>;
|
|
822
859
|
|
|
823
860
|
/**
|
|
824
861
|
* 加载资源
|
|
825
862
|
* @param assetProperty
|
|
826
863
|
*/
|
|
827
|
-
loadAsset<T extends cc.Asset>(
|
|
864
|
+
loadAsset<T extends cc.Asset>(
|
|
865
|
+
assetProperty: AssetProperty,
|
|
866
|
+
cb?: () => void
|
|
867
|
+
): Promise<T>;
|
|
828
868
|
|
|
829
869
|
/**
|
|
830
870
|
* 获取资源
|
|
@@ -972,7 +1012,10 @@ declare namespace FW {
|
|
|
972
1012
|
* @param url
|
|
973
1013
|
* @param cb
|
|
974
1014
|
*/
|
|
975
|
-
loadRemote<T extends cc.Asset = cc.Asset>(
|
|
1015
|
+
loadRemote<T extends cc.Asset = cc.Asset>(
|
|
1016
|
+
url: string,
|
|
1017
|
+
cb?: (asset: cc.Asset) => T
|
|
1018
|
+
): Promise<T>;
|
|
976
1019
|
/**
|
|
977
1020
|
* 从远程加载spine动画
|
|
978
1021
|
* @param data
|
|
@@ -1036,7 +1079,11 @@ declare namespace FW {
|
|
|
1036
1079
|
};
|
|
1037
1080
|
type LayerController = {
|
|
1038
1081
|
readonly entry: FW.Entry;
|
|
1039
|
-
|
|
1082
|
+
logic?: Logic;
|
|
1083
|
+
config?: Config;
|
|
1084
|
+
data?: Data;
|
|
1085
|
+
sender?: SocketSender;
|
|
1086
|
+
handle?: SocketHandle;
|
|
1040
1087
|
layerData: LayerData;
|
|
1041
1088
|
/** uuid */
|
|
1042
1089
|
uuid: string;
|
|
@@ -1084,7 +1131,7 @@ declare namespace FW {
|
|
|
1084
1131
|
referenceNode: cc.Node,
|
|
1085
1132
|
type?: {
|
|
1086
1133
|
prototype: T;
|
|
1087
|
-
}
|
|
1134
|
+
}
|
|
1088
1135
|
): T;
|
|
1089
1136
|
/** 指定注册CC事件 */
|
|
1090
1137
|
registerCCEvent(eventName: string, event: FW.CCEvent | FW.CCEvent[]): void;
|
|
@@ -1248,7 +1295,7 @@ declare namespace FW {
|
|
|
1248
1295
|
*/
|
|
1249
1296
|
register(
|
|
1250
1297
|
state: FW.StateMachineRegisterArgs | FW.StateMachineRegisterArgs[],
|
|
1251
|
-
stateMachineName?: string
|
|
1298
|
+
stateMachineName?: string
|
|
1252
1299
|
);
|
|
1253
1300
|
/**
|
|
1254
1301
|
* 注销指定状态机的某个状态
|
|
@@ -1304,22 +1351,22 @@ declare namespace FW {
|
|
|
1304
1351
|
progress: Function;
|
|
1305
1352
|
easing: Function | String;
|
|
1306
1353
|
onUpdate: Function;
|
|
1307
|
-
}
|
|
1354
|
+
}>
|
|
1308
1355
|
>(
|
|
1309
1356
|
duration: number,
|
|
1310
1357
|
props: ConstructorType<T>,
|
|
1311
|
-
opts?: OPTS
|
|
1358
|
+
opts?: OPTS
|
|
1312
1359
|
): FW.Tween;
|
|
1313
1360
|
by<
|
|
1314
1361
|
OPTS extends Partial<{
|
|
1315
1362
|
progress: Function;
|
|
1316
1363
|
easing: Function | String;
|
|
1317
1364
|
onUpdate: Function;
|
|
1318
|
-
}
|
|
1365
|
+
}>
|
|
1319
1366
|
>(
|
|
1320
1367
|
duration: number,
|
|
1321
1368
|
props: ConstructorType<T>,
|
|
1322
|
-
opts?: OPTS
|
|
1369
|
+
opts?: OPTS
|
|
1323
1370
|
): FW.Tween;
|
|
1324
1371
|
set(props: ConstructorType<T>): FW.Tween;
|
|
1325
1372
|
};
|
|
@@ -1564,7 +1611,11 @@ declare namespace FW {
|
|
|
1564
1611
|
* @param volume
|
|
1565
1612
|
* @param loop
|
|
1566
1613
|
*/
|
|
1567
|
-
playMusic(
|
|
1614
|
+
playMusic(
|
|
1615
|
+
assetProperty: AssetProperty,
|
|
1616
|
+
volume?: number,
|
|
1617
|
+
loop?: boolean
|
|
1618
|
+
): void;
|
|
1568
1619
|
/**
|
|
1569
1620
|
* 停止背景音乐
|
|
1570
1621
|
*/
|
|
@@ -1593,21 +1644,36 @@ declare namespace FW {
|
|
|
1593
1644
|
* @param volume
|
|
1594
1645
|
* @param loop
|
|
1595
1646
|
*/
|
|
1596
|
-
play(
|
|
1647
|
+
play(
|
|
1648
|
+
path: string,
|
|
1649
|
+
cb?: (id: number) => void,
|
|
1650
|
+
volume?: number,
|
|
1651
|
+
loop?: boolean
|
|
1652
|
+
);
|
|
1597
1653
|
/**
|
|
1598
1654
|
* 播放音效
|
|
1599
1655
|
* @param audio
|
|
1600
1656
|
* @param volume
|
|
1601
1657
|
* @param loop
|
|
1602
1658
|
*/
|
|
1603
|
-
play(
|
|
1659
|
+
play(
|
|
1660
|
+
audio: cc.AudioClip,
|
|
1661
|
+
cb?: (id: number) => void,
|
|
1662
|
+
volume?: number,
|
|
1663
|
+
loop?: boolean
|
|
1664
|
+
);
|
|
1604
1665
|
/**
|
|
1605
1666
|
* 播放音效
|
|
1606
1667
|
* @param assetProperty
|
|
1607
1668
|
* @param volume
|
|
1608
1669
|
* @param loop
|
|
1609
1670
|
*/
|
|
1610
|
-
play(
|
|
1671
|
+
play(
|
|
1672
|
+
assetProperty: AssetProperty,
|
|
1673
|
+
cb?: (id: number) => void,
|
|
1674
|
+
volume?: number,
|
|
1675
|
+
loop?: boolean
|
|
1676
|
+
);
|
|
1611
1677
|
/**
|
|
1612
1678
|
* 暂停所有
|
|
1613
1679
|
*/
|
|
@@ -1628,7 +1694,11 @@ declare namespace FW {
|
|
|
1628
1694
|
};
|
|
1629
1695
|
|
|
1630
1696
|
type PerformanceManager = {
|
|
1631
|
-
recordOperationMetric(
|
|
1697
|
+
recordOperationMetric(
|
|
1698
|
+
manager: string,
|
|
1699
|
+
operation: string,
|
|
1700
|
+
duration: number
|
|
1701
|
+
): void;
|
|
1632
1702
|
getModuleReport(manager: string): PerformanceReport;
|
|
1633
1703
|
getAllReports(): Map<string, FW.PerformanceReport>;
|
|
1634
1704
|
};
|
|
@@ -1927,7 +1997,7 @@ declare namespace FW {
|
|
|
1927
1997
|
abort?: (reason?: any) => void;
|
|
1928
1998
|
addAbortEventListener?: (
|
|
1929
1999
|
listener: (this: AbortSignal, ev: Event) => any,
|
|
1930
|
-
options?: boolean | AddEventListenerOptions
|
|
2000
|
+
options?: boolean | AddEventListenerOptions
|
|
1931
2001
|
) => void;
|
|
1932
2002
|
};
|
|
1933
2003
|
|
|
@@ -1935,7 +2005,7 @@ declare namespace FW {
|
|
|
1935
2005
|
resolve: (value: T | PromiseLike<T>) => void,
|
|
1936
2006
|
reject: (reason?: any) => void,
|
|
1937
2007
|
signal: AbortSignal,
|
|
1938
|
-
reason?: any
|
|
2008
|
+
reason?: any
|
|
1939
2009
|
) => void;
|
|
1940
2010
|
|
|
1941
2011
|
type PromiseExecuteOptions = {
|
|
@@ -1946,7 +2016,10 @@ declare namespace FW {
|
|
|
1946
2016
|
retryCondition?: (error: any, retryCount: number) => boolean;
|
|
1947
2017
|
};
|
|
1948
2018
|
|
|
1949
|
-
type Promise = (
|
|
2019
|
+
type Promise = (
|
|
2020
|
+
resolve: (value: any) => void,
|
|
2021
|
+
reject: (reason?: any) => void
|
|
2022
|
+
) => void;
|
|
1950
2023
|
|
|
1951
2024
|
type PromiseResult<T = any> = {
|
|
1952
2025
|
success: PromiseProxy<T>[];
|
|
@@ -1954,7 +2027,7 @@ declare namespace FW {
|
|
|
1954
2027
|
cancelled: number[];
|
|
1955
2028
|
};
|
|
1956
2029
|
|
|
1957
|
-
type PromiseStatus =
|
|
2030
|
+
type PromiseStatus = "pending" | "fulfilled" | "rejected" | "cancelled";
|
|
1958
2031
|
|
|
1959
2032
|
/**
|
|
1960
2033
|
* 性能管理器配置
|
package/Framework.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { Container, interfaces } from
|
|
3
|
-
import { FWSystemDefine } from
|
|
4
|
-
import FWLog from
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
import { Container, interfaces } from "inversify";
|
|
3
|
+
import { FWSystemDefine } from "./define/FWSystemDefine";
|
|
4
|
+
import FWLog from "./log/FWLog";
|
|
5
|
+
import { FWEventDefine } from "./define/FWEventDefine";
|
|
6
|
+
import { FrameworkBase } from "./FrameworkBase";
|
|
5
7
|
|
|
6
8
|
class Framework {
|
|
7
9
|
private container: Container;
|
|
@@ -12,7 +14,7 @@ class Framework {
|
|
|
12
14
|
|
|
13
15
|
initialize() {
|
|
14
16
|
this.container = new Container({
|
|
15
|
-
defaultScope:
|
|
17
|
+
defaultScope: "Singleton",
|
|
16
18
|
autoBindInjectable: true,
|
|
17
19
|
});
|
|
18
20
|
this.registry = new Map<string, new () => FW.Registry>();
|
|
@@ -32,11 +34,11 @@ class Framework {
|
|
|
32
34
|
|
|
33
35
|
/** 获取组件 */
|
|
34
36
|
public getComponent<T>(serviceIdentifier: FW.ServiceIdentifier<T>): T {
|
|
35
|
-
if (typeof serviceIdentifier ===
|
|
37
|
+
if (typeof serviceIdentifier === "string") {
|
|
36
38
|
if (this.container.isBound(serviceIdentifier)) {
|
|
37
39
|
return this.container.get<T>(serviceIdentifier);
|
|
38
40
|
}
|
|
39
|
-
} else if (typeof serviceIdentifier ===
|
|
41
|
+
} else if (typeof serviceIdentifier === "function") {
|
|
40
42
|
const className = serviceIdentifier.name;
|
|
41
43
|
|
|
42
44
|
if (this.container.isBound(serviceIdentifier)) {
|
|
@@ -51,7 +53,9 @@ class Framework {
|
|
|
51
53
|
Handle: FWSystemDefine.FWBindTag.HANDLE,
|
|
52
54
|
};
|
|
53
55
|
|
|
54
|
-
const [suffix] =
|
|
56
|
+
const [suffix] =
|
|
57
|
+
Object.entries(suffixMap).find(([key]) => className.endsWith(key)) ||
|
|
58
|
+
[];
|
|
55
59
|
|
|
56
60
|
if (suffix) {
|
|
57
61
|
const bundleName = FW.Entry.bundleName;
|
|
@@ -83,10 +87,8 @@ class Framework {
|
|
|
83
87
|
const instances: T[] = [];
|
|
84
88
|
for (const binding of childBindings) {
|
|
85
89
|
try {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
instances.push(instance);
|
|
89
|
-
}
|
|
90
|
+
const instance = this.getComponent<T>(binding.serviceIdentifier as any);
|
|
91
|
+
instances.push(instance);
|
|
90
92
|
} catch (e) {
|
|
91
93
|
throw new Error(e);
|
|
92
94
|
}
|
|
@@ -129,7 +131,10 @@ class Framework {
|
|
|
129
131
|
*/
|
|
130
132
|
createRegistry(bundleName: string): FW.Registry {
|
|
131
133
|
if (!this.registry.has(bundleName)) return;
|
|
132
|
-
this.container
|
|
134
|
+
this.container
|
|
135
|
+
.bind(this.registry.get(bundleName))
|
|
136
|
+
.toSelf()
|
|
137
|
+
.inSingletonScope();
|
|
133
138
|
return this.getRegistry(bundleName);
|
|
134
139
|
}
|
|
135
140
|
|
|
@@ -147,7 +152,13 @@ class Framework {
|
|
|
147
152
|
* @param data
|
|
148
153
|
*/
|
|
149
154
|
register(data: FW.RegisterFramework) {
|
|
150
|
-
const classes = [
|
|
155
|
+
const classes = [
|
|
156
|
+
data.logic,
|
|
157
|
+
data.data,
|
|
158
|
+
data.config,
|
|
159
|
+
data.sender,
|
|
160
|
+
data.handle,
|
|
161
|
+
];
|
|
151
162
|
classes.forEach((cls, index) => {
|
|
152
163
|
if (cls && !this.container.isBound(cls)) {
|
|
153
164
|
this.container.bind(cls).toSelf().inSingletonScope();
|
|
@@ -156,6 +167,17 @@ class Framework {
|
|
|
156
167
|
});
|
|
157
168
|
|
|
158
169
|
this.recordRegistration(data);
|
|
170
|
+
|
|
171
|
+
classes.forEach((cls) => {
|
|
172
|
+
if (cls && this.container.isBound(cls)) {
|
|
173
|
+
try {
|
|
174
|
+
const instance = this.container.get(cls) as FrameworkBase;
|
|
175
|
+
instance?.initializeDependencies?.();
|
|
176
|
+
} catch (error) {
|
|
177
|
+
FWLog.warn(`Error initializing dependencies for ${cls.name}:`, error);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
});
|
|
159
181
|
}
|
|
160
182
|
|
|
161
183
|
/**
|
|
@@ -164,15 +186,21 @@ class Framework {
|
|
|
164
186
|
* @returns
|
|
165
187
|
*/
|
|
166
188
|
unRegister(data: FW.RegisterFramework) {
|
|
167
|
-
const classes = [
|
|
189
|
+
const classes = [
|
|
190
|
+
data.logic,
|
|
191
|
+
data.data,
|
|
192
|
+
data.config,
|
|
193
|
+
data.sender,
|
|
194
|
+
data.handle,
|
|
195
|
+
];
|
|
168
196
|
classes.forEach((cls, index) => {
|
|
169
197
|
const key = this.getKey(data.bundleName, index);
|
|
170
198
|
if (cls && this.container.isBound(cls)) {
|
|
171
|
-
this.container.get(key)?.[
|
|
199
|
+
this.container.get(key)?.["onDestroy"]?.();
|
|
172
200
|
this.container.unbind(cls);
|
|
173
201
|
}
|
|
174
202
|
if (this.container.isBound(key)) {
|
|
175
|
-
this.container.get(key)?.[
|
|
203
|
+
this.container.get(key)?.["onDestroy"]?.();
|
|
176
204
|
this.container.unbind(this.getKey(data.bundleName, index));
|
|
177
205
|
}
|
|
178
206
|
});
|
|
@@ -188,7 +216,10 @@ class Framework {
|
|
|
188
216
|
|
|
189
217
|
const registrations = this.registeredComponents.get(bundleName)!;
|
|
190
218
|
const exists = registrations.some(
|
|
191
|
-
(reg) =>
|
|
219
|
+
(reg) =>
|
|
220
|
+
reg.logic === data.logic &&
|
|
221
|
+
reg.data === data.data &&
|
|
222
|
+
reg.config === data.config
|
|
192
223
|
);
|
|
193
224
|
|
|
194
225
|
if (!exists) {
|
|
@@ -201,7 +232,10 @@ class Framework {
|
|
|
201
232
|
if (this.registeredComponents.has(bundleName)) {
|
|
202
233
|
const registrations = this.registeredComponents.get(bundleName)!;
|
|
203
234
|
const index = registrations.findIndex(
|
|
204
|
-
(reg) =>
|
|
235
|
+
(reg) =>
|
|
236
|
+
reg.logic === data.logic &&
|
|
237
|
+
reg.data === data.data &&
|
|
238
|
+
reg.config === data.config
|
|
205
239
|
);
|
|
206
240
|
|
|
207
241
|
if (index !== -1) {
|
|
@@ -218,7 +252,7 @@ class Framework {
|
|
|
218
252
|
this.destroyAllComponents();
|
|
219
253
|
this.container.unbindAll();
|
|
220
254
|
this.container = new Container({
|
|
221
|
-
defaultScope:
|
|
255
|
+
defaultScope: "Singleton",
|
|
222
256
|
autoBindInjectable: true,
|
|
223
257
|
});
|
|
224
258
|
|
|
@@ -234,7 +268,7 @@ class Framework {
|
|
|
234
268
|
try {
|
|
235
269
|
if (this.container.isBound(binding.serviceIdentifier)) {
|
|
236
270
|
const instance = this.container.get(binding.serviceIdentifier);
|
|
237
|
-
instance?.[
|
|
271
|
+
instance?.["onDestroy"]?.();
|
|
238
272
|
}
|
|
239
273
|
} catch (e) {
|
|
240
274
|
FWLog.warn(`Error destroying component ${key}:`, e);
|
|
@@ -244,12 +278,18 @@ class Framework {
|
|
|
244
278
|
}
|
|
245
279
|
|
|
246
280
|
private reregisterAllComponents(): void {
|
|
247
|
-
for (const [
|
|
281
|
+
for (const [
|
|
282
|
+
bundleName,
|
|
283
|
+
registrations,
|
|
284
|
+
] of this.registeredComponents.entries()) {
|
|
248
285
|
for (const data of registrations) {
|
|
249
286
|
try {
|
|
250
287
|
this.register(data);
|
|
251
288
|
} catch (e) {
|
|
252
|
-
console.error(
|
|
289
|
+
console.error(
|
|
290
|
+
`Error re-registering component for bundle ${bundleName}:`,
|
|
291
|
+
e
|
|
292
|
+
);
|
|
253
293
|
}
|
|
254
294
|
}
|
|
255
295
|
}
|
|
@@ -264,7 +304,7 @@ class Framework {
|
|
|
264
304
|
}
|
|
265
305
|
|
|
266
306
|
private isSubclassOf(child: any, parent: any): boolean {
|
|
267
|
-
if (typeof child !==
|
|
307
|
+
if (typeof child !== "function" || typeof parent !== "function") {
|
|
268
308
|
return false;
|
|
269
309
|
}
|
|
270
310
|
let current = child;
|