@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
package/FW.d.ts
CHANGED
|
@@ -6,18 +6,13 @@ declare namespace FW {
|
|
|
6
6
|
prototype: T;
|
|
7
7
|
};
|
|
8
8
|
|
|
9
|
-
type ServiceIdentifierData<TInstance = unknown> =
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
type
|
|
16
|
-
TInstance = unknown,
|
|
17
|
-
TArgs extends unknown[] = any[]
|
|
18
|
-
> = Newable<TInstance, TArgs>;
|
|
19
|
-
type CommonServiceIdentifier<TInstance = unknown> =
|
|
20
|
-
ServiceIdentifierData<TInstance>;
|
|
9
|
+
type ServiceIdentifierData<TInstance = unknown> = string | symbol | Newable<TInstance> | Function;
|
|
10
|
+
|
|
11
|
+
type CommonNewable<TInstance = unknown, TArgs extends unknown[] = any[]> = Newable<
|
|
12
|
+
TInstance,
|
|
13
|
+
TArgs
|
|
14
|
+
>;
|
|
15
|
+
type CommonServiceIdentifier<TInstance = unknown> = ServiceIdentifierData<TInstance>;
|
|
21
16
|
|
|
22
17
|
type ServiceIdentifier<T = unknown> = CommonServiceIdentifier<T>;
|
|
23
18
|
/**
|
|
@@ -63,13 +58,13 @@ declare namespace FW {
|
|
|
63
58
|
resolve: (value: T | PromiseLike<T>) => void,
|
|
64
59
|
reject: (reason?: any) => void,
|
|
65
60
|
signal?: AbortSignal,
|
|
66
|
-
reason?: any
|
|
61
|
+
reason?: any,
|
|
67
62
|
) => void = PromiseExcutor,
|
|
68
|
-
options: PromiseExecuteOptions = {}
|
|
63
|
+
options: PromiseExecuteOptions = {},
|
|
69
64
|
): PromiseProxy<T>;
|
|
70
65
|
all<T = any>(
|
|
71
66
|
promises: FW.PromiseProxy<T>[],
|
|
72
|
-
options: FW.PromiseExecuteOptions = {}
|
|
67
|
+
options: FW.PromiseExecuteOptions = {},
|
|
73
68
|
): FW.PromiseProxy<FW.PromiseResult<T>>;
|
|
74
69
|
};
|
|
75
70
|
|
|
@@ -84,22 +79,18 @@ declare namespace FW {
|
|
|
84
79
|
registerLanguagePackageEnum(
|
|
85
80
|
bundleName: string,
|
|
86
81
|
language: any,
|
|
87
|
-
getter: (key: string, language?: string) => string
|
|
82
|
+
getter: (key: string, language?: string) => string,
|
|
88
83
|
): void;
|
|
89
84
|
getSupportedLanguages(): string[];
|
|
90
85
|
setSupportedLanguages(languages: string[]): void;
|
|
91
86
|
getBundles(): string[];
|
|
92
87
|
getLanguage(): string;
|
|
93
88
|
getLanguageIndex(): number;
|
|
94
|
-
getLanguagePackageValue(
|
|
95
|
-
bundleName: string,
|
|
96
|
-
key: string,
|
|
97
|
-
language?: string
|
|
98
|
-
): string;
|
|
89
|
+
getLanguagePackageValue(bundleName: string, key: string, language?: string): string;
|
|
99
90
|
getLanguagePackageEnumKeys(bundleName: string): string[];
|
|
100
91
|
getLanguagePackageEnumValues(bundleName: string): string[];
|
|
101
92
|
getLanguagePackageEnum<K extends keyof ILanguageBundleAccessor>(
|
|
102
|
-
bundleName: K
|
|
93
|
+
bundleName: K,
|
|
103
94
|
): ILanguageBundleAccessor[K];
|
|
104
95
|
initializeLanguage(language: string);
|
|
105
96
|
};
|
|
@@ -159,32 +150,32 @@ declare namespace FW {
|
|
|
159
150
|
createObjectPool<T extends FWObject = FWObject>(
|
|
160
151
|
node: cc.Node,
|
|
161
152
|
parent: cc.Node,
|
|
162
|
-
tag?: string
|
|
153
|
+
tag?: string,
|
|
163
154
|
): Promise<ObjectPool<T>>;
|
|
164
155
|
createObjectPool<T extends FWObject = FWObject>(
|
|
165
156
|
prefab: cc.Prefab,
|
|
166
157
|
parent: cc.Node,
|
|
167
|
-
tag?: string
|
|
158
|
+
tag?: string,
|
|
168
159
|
): Promise<ObjectPool<T>>;
|
|
169
160
|
createObjectPool<T extends FWObject = FWObject>(
|
|
170
161
|
assetProperty: FW.AssetProperty,
|
|
171
162
|
parent: cc.Node,
|
|
172
|
-
tag?: string
|
|
163
|
+
tag?: string,
|
|
173
164
|
): Promise<ObjectPool<T>>;
|
|
174
165
|
createObjectPool<T extends FWObject = FWObject>(
|
|
175
166
|
node: cc.Node,
|
|
176
167
|
parent: cc.Node,
|
|
177
|
-
type?: number
|
|
168
|
+
type?: number,
|
|
178
169
|
): Promise<ObjectPool<T>>;
|
|
179
170
|
createObjectPool<T extends FWObject = FWObject>(
|
|
180
171
|
prefab: cc.Prefab,
|
|
181
172
|
parent: cc.Node,
|
|
182
|
-
type?: number
|
|
173
|
+
type?: number,
|
|
183
174
|
): Promise<ObjectPool<T>>;
|
|
184
175
|
createObjectPool<T extends FWObject = FWObject>(
|
|
185
176
|
assetProperty: FW.AssetProperty,
|
|
186
177
|
parent: cc.Node,
|
|
187
|
-
type?: number
|
|
178
|
+
type?: number,
|
|
188
179
|
): Promise<ObjectPool<T>>;
|
|
189
180
|
/** 获取已经创建的对象池 */
|
|
190
181
|
getObjectPool(tag: string): ObjectPool;
|
|
@@ -217,7 +208,7 @@ declare namespace FW {
|
|
|
217
208
|
address: string,
|
|
218
209
|
sender: SocketSender,
|
|
219
210
|
handle: SocketHandle,
|
|
220
|
-
config: SocketConfig
|
|
211
|
+
config: SocketConfig,
|
|
221
212
|
): Promise<Socket>;
|
|
222
213
|
/**
|
|
223
214
|
* 获取socket
|
|
@@ -313,7 +304,7 @@ declare namespace FW {
|
|
|
313
304
|
tag: string,
|
|
314
305
|
sender: SocketSender,
|
|
315
306
|
handle: SocketHandle,
|
|
316
|
-
config: SocketConfig
|
|
307
|
+
config: SocketConfig,
|
|
317
308
|
): SocketPromiseProxy;
|
|
318
309
|
};
|
|
319
310
|
|
|
@@ -348,7 +339,7 @@ declare namespace FW {
|
|
|
348
339
|
args7?: FW.EventManagerArgs,
|
|
349
340
|
args8?: FW.EventManagerArgs,
|
|
350
341
|
args9?: FW.EventManagerArgs,
|
|
351
|
-
args10?: FW.EventManagerArgs
|
|
342
|
+
args10?: FW.EventManagerArgs,
|
|
352
343
|
);
|
|
353
344
|
/**
|
|
354
345
|
* 比较目标
|
|
@@ -409,35 +400,19 @@ declare namespace FW {
|
|
|
409
400
|
/**
|
|
410
401
|
* 一次性调度器
|
|
411
402
|
*/
|
|
412
|
-
scheduleOnce(
|
|
413
|
-
cb?: () => void,
|
|
414
|
-
time?: number,
|
|
415
|
-
tag?: string
|
|
416
|
-
): FW.TimerSchedule;
|
|
403
|
+
scheduleOnce(cb?: () => void, time?: number, tag?: string): FW.TimerSchedule;
|
|
417
404
|
/**
|
|
418
405
|
* 一次性调度器
|
|
419
406
|
*/
|
|
420
|
-
scheduleOnce(
|
|
421
|
-
time?: number,
|
|
422
|
-
cb?: () => void,
|
|
423
|
-
tag?: string
|
|
424
|
-
): FW.TimerSchedule;
|
|
407
|
+
scheduleOnce(time?: number, cb?: () => void, tag?: string): FW.TimerSchedule;
|
|
425
408
|
/**
|
|
426
409
|
* 一次性调度器
|
|
427
410
|
*/
|
|
428
|
-
scheduleOnce(
|
|
429
|
-
time?: number,
|
|
430
|
-
cb?: () => void,
|
|
431
|
-
target?: any
|
|
432
|
-
): FW.TimerSchedule;
|
|
411
|
+
scheduleOnce(time?: number, cb?: () => void, target?: any): FW.TimerSchedule;
|
|
433
412
|
/**
|
|
434
413
|
* 一次性调度器
|
|
435
414
|
*/
|
|
436
|
-
scheduleOnce(
|
|
437
|
-
cb?: () => void,
|
|
438
|
-
time?: number,
|
|
439
|
-
target?: any
|
|
440
|
-
): FW.TimerSchedule;
|
|
415
|
+
scheduleOnce(cb?: () => void, time?: number, target?: any): FW.TimerSchedule;
|
|
441
416
|
/**
|
|
442
417
|
* 自定义调度器
|
|
443
418
|
* */
|
|
@@ -446,7 +421,7 @@ declare namespace FW {
|
|
|
446
421
|
time?: number,
|
|
447
422
|
repeat?: number,
|
|
448
423
|
target?: TargetType,
|
|
449
|
-
tag?: string
|
|
424
|
+
tag?: string,
|
|
450
425
|
): TimerSchedule;
|
|
451
426
|
/** 暂停调度器 */
|
|
452
427
|
pauseSchedule(tag: string): void;
|
|
@@ -497,13 +472,13 @@ declare namespace FW {
|
|
|
497
472
|
args7?: EventManagerArgs,
|
|
498
473
|
args8?: EventManagerArgs,
|
|
499
474
|
args9?: EventManagerArgs,
|
|
500
|
-
args10?: EventManagerArgs
|
|
475
|
+
args10?: EventManagerArgs,
|
|
501
476
|
) => void,
|
|
502
477
|
target: TargetType,
|
|
503
478
|
options?: {
|
|
504
479
|
priority?: FWSystemDefine.FWPriorityOrder;
|
|
505
480
|
intercept?: boolean;
|
|
506
|
-
}
|
|
481
|
+
},
|
|
507
482
|
);
|
|
508
483
|
|
|
509
484
|
registerOnce(
|
|
@@ -518,13 +493,13 @@ declare namespace FW {
|
|
|
518
493
|
args7?: EventManagerArgs,
|
|
519
494
|
args8?: EventManagerArgs,
|
|
520
495
|
args9?: EventManagerArgs,
|
|
521
|
-
args10?: EventManagerArgs
|
|
496
|
+
args10?: EventManagerArgs,
|
|
522
497
|
) => void,
|
|
523
498
|
target: TargetType,
|
|
524
499
|
options?: {
|
|
525
500
|
priority?: number;
|
|
526
501
|
intercept?: boolean;
|
|
527
|
-
}
|
|
502
|
+
},
|
|
528
503
|
): void;
|
|
529
504
|
|
|
530
505
|
/**
|
|
@@ -558,7 +533,7 @@ declare namespace FW {
|
|
|
558
533
|
args7?: FW.EventManagerArgs,
|
|
559
534
|
args8?: FW.EventManagerArgs,
|
|
560
535
|
args9?: FW.EventManagerArgs,
|
|
561
|
-
args10?: FW.EventManagerArgs
|
|
536
|
+
args10?: FW.EventManagerArgs,
|
|
562
537
|
): void;
|
|
563
538
|
/**
|
|
564
539
|
* 注销事件
|
|
@@ -704,23 +679,19 @@ declare namespace FW {
|
|
|
704
679
|
* @param data
|
|
705
680
|
*/
|
|
706
681
|
openAsync<Ctr extends FWLayerController = FWLayerController>(
|
|
707
|
-
data: LayerOpenArgs<Ctr
|
|
682
|
+
data: LayerOpenArgs<Ctr>,
|
|
708
683
|
): Promise<Ctr>;
|
|
709
684
|
|
|
710
685
|
/**
|
|
711
686
|
* 同步打开layer
|
|
712
687
|
* @param data
|
|
713
688
|
*/
|
|
714
|
-
openSync<Ctr extends FWLayerController = FWLayerController>(
|
|
715
|
-
data: LayerOpenArgs<Ctr>
|
|
716
|
-
): Ctr;
|
|
689
|
+
openSync<Ctr extends FWLayerController = FWLayerController>(data: LayerOpenArgs<Ctr>): Ctr;
|
|
717
690
|
/**
|
|
718
691
|
* 显示常驻layer
|
|
719
692
|
* @param layer
|
|
720
693
|
*/
|
|
721
|
-
displayLayer<Ctr extends FWLayerController = FWLayerController>(
|
|
722
|
-
ctr: Ctr
|
|
723
|
-
): Ctr;
|
|
694
|
+
displayLayer<Ctr extends FWLayerController = FWLayerController>(ctr: Ctr): Ctr;
|
|
724
695
|
/**
|
|
725
696
|
* 隐藏常驻layer
|
|
726
697
|
* @param layer
|
|
@@ -730,9 +701,7 @@ declare namespace FW {
|
|
|
730
701
|
* 关闭layer
|
|
731
702
|
* @param layer
|
|
732
703
|
*/
|
|
733
|
-
close<Ctr extends FWLayerController = FWLayerController>(
|
|
734
|
-
ctr: Ctr
|
|
735
|
-
): FWLayerController;
|
|
704
|
+
close<Ctr extends FWLayerController = FWLayerController>(ctr: Ctr): FWLayerController;
|
|
736
705
|
|
|
737
706
|
/**
|
|
738
707
|
* 从栈关闭
|
|
@@ -801,8 +770,6 @@ declare namespace FW {
|
|
|
801
770
|
};
|
|
802
771
|
|
|
803
772
|
type ResManager = {
|
|
804
|
-
assetMgr: AssetManager;
|
|
805
|
-
bundleMgr: BundleManager;
|
|
806
773
|
initialize(): void;
|
|
807
774
|
onDestroy(): void;
|
|
808
775
|
|
|
@@ -840,10 +807,7 @@ declare namespace FW {
|
|
|
840
807
|
* @param url
|
|
841
808
|
* @param cb
|
|
842
809
|
*/
|
|
843
|
-
loadRemote<T extends cc.Asset = cc.Asset>(
|
|
844
|
-
url: string,
|
|
845
|
-
cb?: (asset: cc.Asset) => T
|
|
846
|
-
): Promise<T>;
|
|
810
|
+
loadRemote<T extends cc.Asset = cc.Asset>(url: string, cb?: (asset: cc.Asset) => T): Promise<T>;
|
|
847
811
|
/**
|
|
848
812
|
* 从远程加载spine动画
|
|
849
813
|
* @param data
|
|
@@ -859,18 +823,13 @@ declare namespace FW {
|
|
|
859
823
|
* 加载资源返回数据
|
|
860
824
|
* @param assetProperty
|
|
861
825
|
*/
|
|
862
|
-
loadAssetData<T extends cc.Asset>(
|
|
863
|
-
assetProperty: AssetProperty
|
|
864
|
-
): Promise<AssetData>;
|
|
826
|
+
loadAssetData<T extends cc.Asset>(assetProperty: AssetProperty): Promise<AssetData>;
|
|
865
827
|
|
|
866
828
|
/**
|
|
867
829
|
* 加载资源
|
|
868
830
|
* @param assetProperty
|
|
869
831
|
*/
|
|
870
|
-
loadAsset<T extends cc.Asset>(
|
|
871
|
-
assetProperty: AssetProperty,
|
|
872
|
-
cb?: () => void
|
|
873
|
-
): Promise<T>;
|
|
832
|
+
loadAsset<T extends cc.Asset>(assetProperty: AssetProperty, cb?: () => void): Promise<T>;
|
|
874
833
|
|
|
875
834
|
/**
|
|
876
835
|
* 获取资源
|
|
@@ -1018,10 +977,7 @@ declare namespace FW {
|
|
|
1018
977
|
* @param url
|
|
1019
978
|
* @param cb
|
|
1020
979
|
*/
|
|
1021
|
-
loadRemote<T extends cc.Asset = cc.Asset>(
|
|
1022
|
-
url: string,
|
|
1023
|
-
cb?: (asset: cc.Asset) => T
|
|
1024
|
-
): Promise<T>;
|
|
980
|
+
loadRemote<T extends cc.Asset = cc.Asset>(url: string, cb?: (asset: cc.Asset) => T): Promise<T>;
|
|
1025
981
|
/**
|
|
1026
982
|
* 从远程加载spine动画
|
|
1027
983
|
* @param data
|
|
@@ -1137,7 +1093,7 @@ declare namespace FW {
|
|
|
1137
1093
|
referenceNode: cc.Node,
|
|
1138
1094
|
type?: {
|
|
1139
1095
|
prototype: T;
|
|
1140
|
-
}
|
|
1096
|
+
},
|
|
1141
1097
|
): T;
|
|
1142
1098
|
registerEvent(args: RegisterArgs): void;
|
|
1143
1099
|
unRegisterEvent(args: RegisterArgs);
|
|
@@ -1314,7 +1270,7 @@ declare namespace FW {
|
|
|
1314
1270
|
*/
|
|
1315
1271
|
register(
|
|
1316
1272
|
state: FW.StateMachineRegisterArgs | FW.StateMachineRegisterArgs[],
|
|
1317
|
-
stateMachineName?: string
|
|
1273
|
+
stateMachineName?: string,
|
|
1318
1274
|
);
|
|
1319
1275
|
/**
|
|
1320
1276
|
* 注销指定状态机的某个状态
|
|
@@ -1370,22 +1326,22 @@ declare namespace FW {
|
|
|
1370
1326
|
progress: Function;
|
|
1371
1327
|
easing: Function | String;
|
|
1372
1328
|
onUpdate: Function;
|
|
1373
|
-
}
|
|
1329
|
+
}>,
|
|
1374
1330
|
>(
|
|
1375
1331
|
duration: number,
|
|
1376
1332
|
props: ConstructorType<T>,
|
|
1377
|
-
opts?: OPTS
|
|
1333
|
+
opts?: OPTS,
|
|
1378
1334
|
): FW.Tween;
|
|
1379
1335
|
by<
|
|
1380
1336
|
OPTS extends Partial<{
|
|
1381
1337
|
progress: Function;
|
|
1382
1338
|
easing: Function | String;
|
|
1383
1339
|
onUpdate: Function;
|
|
1384
|
-
}
|
|
1340
|
+
}>,
|
|
1385
1341
|
>(
|
|
1386
1342
|
duration: number,
|
|
1387
1343
|
props: ConstructorType<T>,
|
|
1388
|
-
opts?: OPTS
|
|
1344
|
+
opts?: OPTS,
|
|
1389
1345
|
): FW.Tween;
|
|
1390
1346
|
set(props: ConstructorType<T>): FW.Tween;
|
|
1391
1347
|
};
|
|
@@ -1630,11 +1586,7 @@ declare namespace FW {
|
|
|
1630
1586
|
* @param volume
|
|
1631
1587
|
* @param loop
|
|
1632
1588
|
*/
|
|
1633
|
-
playMusic(
|
|
1634
|
-
assetProperty: AssetProperty,
|
|
1635
|
-
volume?: number,
|
|
1636
|
-
loop?: boolean
|
|
1637
|
-
): void;
|
|
1589
|
+
playMusic(assetProperty: AssetProperty, volume?: number, loop?: boolean): void;
|
|
1638
1590
|
/**
|
|
1639
1591
|
* 停止背景音乐
|
|
1640
1592
|
*/
|
|
@@ -1663,36 +1615,21 @@ declare namespace FW {
|
|
|
1663
1615
|
* @param volume
|
|
1664
1616
|
* @param loop
|
|
1665
1617
|
*/
|
|
1666
|
-
play(
|
|
1667
|
-
path: string,
|
|
1668
|
-
cb?: (id: number) => void,
|
|
1669
|
-
volume?: number,
|
|
1670
|
-
loop?: boolean
|
|
1671
|
-
);
|
|
1618
|
+
play(path: string, cb?: (id: number) => void, volume?: number, loop?: boolean);
|
|
1672
1619
|
/**
|
|
1673
1620
|
* 播放音效
|
|
1674
1621
|
* @param audio
|
|
1675
1622
|
* @param volume
|
|
1676
1623
|
* @param loop
|
|
1677
1624
|
*/
|
|
1678
|
-
play(
|
|
1679
|
-
audio: cc.AudioClip,
|
|
1680
|
-
cb?: (id: number) => void,
|
|
1681
|
-
volume?: number,
|
|
1682
|
-
loop?: boolean
|
|
1683
|
-
);
|
|
1625
|
+
play(audio: cc.AudioClip, cb?: (id: number) => void, volume?: number, loop?: boolean);
|
|
1684
1626
|
/**
|
|
1685
1627
|
* 播放音效
|
|
1686
1628
|
* @param assetProperty
|
|
1687
1629
|
* @param volume
|
|
1688
1630
|
* @param loop
|
|
1689
1631
|
*/
|
|
1690
|
-
play(
|
|
1691
|
-
assetProperty: AssetProperty,
|
|
1692
|
-
cb?: (id: number) => void,
|
|
1693
|
-
volume?: number,
|
|
1694
|
-
loop?: boolean
|
|
1695
|
-
);
|
|
1632
|
+
play(assetProperty: AssetProperty, cb?: (id: number) => void, volume?: number, loop?: boolean);
|
|
1696
1633
|
/**
|
|
1697
1634
|
* 暂停所有
|
|
1698
1635
|
*/
|
|
@@ -1713,11 +1650,7 @@ declare namespace FW {
|
|
|
1713
1650
|
};
|
|
1714
1651
|
|
|
1715
1652
|
type PerformanceManager = {
|
|
1716
|
-
recordOperationMetric(
|
|
1717
|
-
manager: string,
|
|
1718
|
-
operation: string,
|
|
1719
|
-
duration: number
|
|
1720
|
-
): void;
|
|
1653
|
+
recordOperationMetric(manager: string, operation: string, duration: number): void;
|
|
1721
1654
|
getModuleReport(manager: string): PerformanceReport;
|
|
1722
1655
|
getAllReports(): Map<string, FW.PerformanceReport>;
|
|
1723
1656
|
};
|
|
@@ -2016,7 +1949,7 @@ declare namespace FW {
|
|
|
2016
1949
|
abort?: (reason?: any) => void;
|
|
2017
1950
|
addAbortEventListener?: (
|
|
2018
1951
|
listener: (this: AbortSignal, ev: Event) => any,
|
|
2019
|
-
options?: boolean | AddEventListenerOptions
|
|
1952
|
+
options?: boolean | AddEventListenerOptions,
|
|
2020
1953
|
) => void;
|
|
2021
1954
|
};
|
|
2022
1955
|
|
|
@@ -2024,7 +1957,7 @@ declare namespace FW {
|
|
|
2024
1957
|
resolve: (value: T | PromiseLike<T>) => void,
|
|
2025
1958
|
reject: (reason?: any) => void,
|
|
2026
1959
|
signal: AbortSignal,
|
|
2027
|
-
reason?: any
|
|
1960
|
+
reason?: any,
|
|
2028
1961
|
) => void;
|
|
2029
1962
|
|
|
2030
1963
|
type PromiseExecuteOptions = {
|
|
@@ -2035,10 +1968,7 @@ declare namespace FW {
|
|
|
2035
1968
|
retryCondition?: (error: any, retryCount: number) => boolean;
|
|
2036
1969
|
};
|
|
2037
1970
|
|
|
2038
|
-
type Promise = (
|
|
2039
|
-
resolve: (value: any) => void,
|
|
2040
|
-
reject: (reason?: any) => void
|
|
2041
|
-
) => void;
|
|
1971
|
+
type Promise = (resolve: (value: any) => void, reject: (reason?: any) => void) => void;
|
|
2042
1972
|
|
|
2043
1973
|
type PromiseResult<T = any> = {
|
|
2044
1974
|
success: PromiseProxy<T>[];
|
|
@@ -2046,7 +1976,7 @@ declare namespace FW {
|
|
|
2046
1976
|
cancelled: number[];
|
|
2047
1977
|
};
|
|
2048
1978
|
|
|
2049
|
-
type PromiseStatus =
|
|
1979
|
+
type PromiseStatus = 'pending' | 'fulfilled' | 'rejected' | 'cancelled';
|
|
2050
1980
|
|
|
2051
1981
|
/**
|
|
2052
1982
|
* 性能管理器配置
|
|
@@ -2094,3 +2024,22 @@ declare namespace FW {
|
|
|
2094
2024
|
declare function timeScale(scale: number);
|
|
2095
2025
|
declare let Entry: Entry;
|
|
2096
2026
|
}
|
|
2027
|
+
|
|
2028
|
+
declare namespace FW {
|
|
2029
|
+
export type Framework = {
|
|
2030
|
+
initialize(): void;
|
|
2031
|
+
addRegistry(bundleName: string, registry: new () => Registry): void;
|
|
2032
|
+
getContainer(): any;
|
|
2033
|
+
getComponent<T>(serviceIdentifier: ServiceIdentifier<T>): T;
|
|
2034
|
+
getComponents<T>(serviceIdentifier: ServiceIdentifier<T>): T[];
|
|
2035
|
+
hasRegistry(bundleName: string): boolean;
|
|
2036
|
+
getRegistry(bundleName: string): Registry;
|
|
2037
|
+
createRegistry(bundleName: string): Registry;
|
|
2038
|
+
destroyRegistry(bundleName: string): void;
|
|
2039
|
+
register(data: RegisterFramework): void;
|
|
2040
|
+
unRegister(data: RegisterFramework): void;
|
|
2041
|
+
restart(): void;
|
|
2042
|
+
getRegisteredComponents(): Map<string, RegisterFramework[]>;
|
|
2043
|
+
};
|
|
2044
|
+
declare let Framework: Framework;
|
|
2045
|
+
}
|
package/Framework.ts
CHANGED
|
@@ -1,44 +1,35 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { Container, interfaces } from
|
|
3
|
-
import { FWSystemDefine } from
|
|
4
|
-
import FWLog from
|
|
5
|
-
import { FWEventDefine } from
|
|
6
|
-
import { FrameworkBase } from
|
|
7
|
-
|
|
8
|
-
class Framework {
|
|
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';
|
|
7
|
+
|
|
8
|
+
export class Framework implements FW.Framework {
|
|
9
9
|
private container: Container;
|
|
10
10
|
private registry: Map<string, new () => FW.Registry>;
|
|
11
11
|
private registeredComponents: Map<string, FW.RegisterFramework[]> = new Map();
|
|
12
|
-
private static instance: Framework;
|
|
13
|
-
private constructor() {}
|
|
14
12
|
|
|
15
13
|
initialize() {
|
|
16
14
|
this.container = new Container({
|
|
17
|
-
defaultScope:
|
|
15
|
+
defaultScope: 'Singleton',
|
|
18
16
|
autoBindInjectable: true,
|
|
19
17
|
});
|
|
20
18
|
this.registry = new Map<string, new () => FW.Registry>();
|
|
21
19
|
this.registeredComponents.clear();
|
|
22
20
|
}
|
|
23
21
|
|
|
24
|
-
public static getInstance() {
|
|
25
|
-
if (!this.instance) {
|
|
26
|
-
this.instance = new Framework();
|
|
27
|
-
}
|
|
28
|
-
return this.instance;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
22
|
public getContainer(): Container {
|
|
32
23
|
return this.container;
|
|
33
24
|
}
|
|
34
25
|
|
|
35
26
|
/** 获取组件 */
|
|
36
27
|
public getComponent<T>(serviceIdentifier: FW.ServiceIdentifier<T>): T {
|
|
37
|
-
if (typeof serviceIdentifier ===
|
|
28
|
+
if (typeof serviceIdentifier === 'string') {
|
|
38
29
|
if (this.container.isBound(serviceIdentifier)) {
|
|
39
30
|
return this.container.get<T>(serviceIdentifier);
|
|
40
31
|
}
|
|
41
|
-
} else if (typeof serviceIdentifier ===
|
|
32
|
+
} else if (typeof serviceIdentifier === 'function') {
|
|
42
33
|
const className = serviceIdentifier.name;
|
|
43
34
|
|
|
44
35
|
if (this.container.isBound(serviceIdentifier)) {
|
|
@@ -53,9 +44,7 @@ class Framework {
|
|
|
53
44
|
Handle: FWSystemDefine.FWBindTag.HANDLE,
|
|
54
45
|
};
|
|
55
46
|
|
|
56
|
-
const [suffix] =
|
|
57
|
-
Object.entries(suffixMap).find(([key]) => className.endsWith(key)) ||
|
|
58
|
-
[];
|
|
47
|
+
const [suffix] = Object.entries(suffixMap).find(([key]) => className.endsWith(key)) || [];
|
|
59
48
|
|
|
60
49
|
if (suffix) {
|
|
61
50
|
const bundleName = FW.Entry.bundleName;
|
|
@@ -131,10 +120,7 @@ class Framework {
|
|
|
131
120
|
*/
|
|
132
121
|
createRegistry(bundleName: string): FW.Registry {
|
|
133
122
|
if (!this.registry.has(bundleName)) return;
|
|
134
|
-
this.container
|
|
135
|
-
.bind(this.registry.get(bundleName))
|
|
136
|
-
.toSelf()
|
|
137
|
-
.inSingletonScope();
|
|
123
|
+
this.container.bind(this.registry.get(bundleName)).toSelf().inSingletonScope();
|
|
138
124
|
return this.getRegistry(bundleName);
|
|
139
125
|
}
|
|
140
126
|
|
|
@@ -152,13 +138,7 @@ class Framework {
|
|
|
152
138
|
* @param data
|
|
153
139
|
*/
|
|
154
140
|
register(data: FW.RegisterFramework) {
|
|
155
|
-
const classes = [
|
|
156
|
-
data.logic,
|
|
157
|
-
data.data,
|
|
158
|
-
data.config,
|
|
159
|
-
data.sender,
|
|
160
|
-
data.handle,
|
|
161
|
-
];
|
|
141
|
+
const classes = [data.logic, data.data, data.config, data.sender, data.handle];
|
|
162
142
|
classes.forEach((cls, index) => {
|
|
163
143
|
if (cls && !this.container.isBound(cls)) {
|
|
164
144
|
this.container.bind(cls).toSelf().inSingletonScope();
|
|
@@ -186,21 +166,15 @@ class Framework {
|
|
|
186
166
|
* @returns
|
|
187
167
|
*/
|
|
188
168
|
unRegister(data: FW.RegisterFramework) {
|
|
189
|
-
const classes = [
|
|
190
|
-
data.logic,
|
|
191
|
-
data.data,
|
|
192
|
-
data.config,
|
|
193
|
-
data.sender,
|
|
194
|
-
data.handle,
|
|
195
|
-
];
|
|
169
|
+
const classes = [data.logic, data.data, data.config, data.sender, data.handle];
|
|
196
170
|
classes.forEach((cls, index) => {
|
|
197
171
|
const key = this.getKey(data.bundleName, index);
|
|
198
172
|
if (cls && this.container.isBound(cls)) {
|
|
199
|
-
this.container.get(key)?.[
|
|
173
|
+
this.container.get(key)?.['onDestroy']?.();
|
|
200
174
|
this.container.unbind(cls);
|
|
201
175
|
}
|
|
202
176
|
if (this.container.isBound(key)) {
|
|
203
|
-
this.container.get(key)?.[
|
|
177
|
+
this.container.get(key)?.['onDestroy']?.();
|
|
204
178
|
this.container.unbind(this.getKey(data.bundleName, index));
|
|
205
179
|
}
|
|
206
180
|
});
|
|
@@ -216,10 +190,7 @@ class Framework {
|
|
|
216
190
|
|
|
217
191
|
const registrations = this.registeredComponents.get(bundleName)!;
|
|
218
192
|
const exists = registrations.some(
|
|
219
|
-
(reg) =>
|
|
220
|
-
reg.logic === data.logic &&
|
|
221
|
-
reg.data === data.data &&
|
|
222
|
-
reg.config === data.config
|
|
193
|
+
(reg) => reg.logic === data.logic && reg.data === data.data && reg.config === data.config,
|
|
223
194
|
);
|
|
224
195
|
|
|
225
196
|
if (!exists) {
|
|
@@ -232,10 +203,7 @@ class Framework {
|
|
|
232
203
|
if (this.registeredComponents.has(bundleName)) {
|
|
233
204
|
const registrations = this.registeredComponents.get(bundleName)!;
|
|
234
205
|
const index = registrations.findIndex(
|
|
235
|
-
(reg) =>
|
|
236
|
-
reg.logic === data.logic &&
|
|
237
|
-
reg.data === data.data &&
|
|
238
|
-
reg.config === data.config
|
|
206
|
+
(reg) => reg.logic === data.logic && reg.data === data.data && reg.config === data.config,
|
|
239
207
|
);
|
|
240
208
|
|
|
241
209
|
if (index !== -1) {
|
|
@@ -252,7 +220,7 @@ class Framework {
|
|
|
252
220
|
this.destroyAllComponents();
|
|
253
221
|
this.container.unbindAll();
|
|
254
222
|
this.container = new Container({
|
|
255
|
-
defaultScope:
|
|
223
|
+
defaultScope: 'Singleton',
|
|
256
224
|
autoBindInjectable: true,
|
|
257
225
|
});
|
|
258
226
|
|
|
@@ -268,7 +236,7 @@ class Framework {
|
|
|
268
236
|
try {
|
|
269
237
|
if (this.container.isBound(binding.serviceIdentifier)) {
|
|
270
238
|
const instance = this.container.get(binding.serviceIdentifier);
|
|
271
|
-
instance?.[
|
|
239
|
+
instance?.['onDestroy']?.();
|
|
272
240
|
}
|
|
273
241
|
} catch (e) {
|
|
274
242
|
FWLog.warn(`Error destroying component ${key}:`, e);
|
|
@@ -278,18 +246,12 @@ class Framework {
|
|
|
278
246
|
}
|
|
279
247
|
|
|
280
248
|
private reregisterAllComponents(): void {
|
|
281
|
-
for (const [
|
|
282
|
-
bundleName,
|
|
283
|
-
registrations,
|
|
284
|
-
] of this.registeredComponents.entries()) {
|
|
249
|
+
for (const [bundleName, registrations] of this.registeredComponents.entries()) {
|
|
285
250
|
for (const data of registrations) {
|
|
286
251
|
try {
|
|
287
252
|
this.register(data);
|
|
288
253
|
} catch (e) {
|
|
289
|
-
console.error(
|
|
290
|
-
`Error re-registering component for bundle ${bundleName}:`,
|
|
291
|
-
e
|
|
292
|
-
);
|
|
254
|
+
console.error(`Error re-registering component for bundle ${bundleName}:`, e);
|
|
293
255
|
}
|
|
294
256
|
}
|
|
295
257
|
}
|
|
@@ -304,7 +266,7 @@ class Framework {
|
|
|
304
266
|
}
|
|
305
267
|
|
|
306
268
|
private isSubclassOf(child: any, parent: any): boolean {
|
|
307
|
-
if (typeof child !==
|
|
269
|
+
if (typeof child !== 'function' || typeof parent !== 'function') {
|
|
308
270
|
return false;
|
|
309
271
|
}
|
|
310
272
|
let current = child;
|
|
@@ -317,5 +279,3 @@ class Framework {
|
|
|
317
279
|
return false;
|
|
318
280
|
}
|
|
319
281
|
}
|
|
320
|
-
|
|
321
|
-
export default Framework.getInstance();
|