dzkcc-mflow 0.0.32 → 0.0.34
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/README.md +1 -1
- package/dist/App.js +0 -1
- package/dist/core/Api.d.ts +13 -40
- package/dist/core/Core.d.ts +10 -10
- package/dist/core/Core.js +24 -24
- package/dist/core/Decorators.d.ts +48 -20
- package/dist/core/Decorators.js +45 -50
- package/dist/core/index.js +1 -1
- package/dist/libs/UIManager.d.ts +9 -9
- package/dist/libs/UIManager.js +19 -19
- package/dist/mflow-tools.zip +0 -0
- package/package.json +1 -4
package/README.md
CHANGED
|
@@ -188,7 +188,7 @@ userModel.name; // ✅ 有完整的代码补全
|
|
|
188
188
|
|
|
189
189
|
> ⚠️ **如果 getManager/getModel 没有类型提示**?
|
|
190
190
|
>
|
|
191
|
-
> 需要创建类型映射文件,使用编辑器的 **mflow-tools -> Generate
|
|
191
|
+
> 需要创建类型映射文件,使用编辑器的 **mflow-tools -> Generate API type hints/生成API类型提示** 自动生成,
|
|
192
192
|
> 或查看 [类型提示问题解决方案](./docs/TYPE_INFERENCE_FIX.md)
|
|
193
193
|
|
|
194
194
|
📖 **查看文档**: [类型自动推断](./docs/TYPE_INFERENCE.md) | [类型生成工具](./docs/TYPE_GENERATION.md) | [类型提示问题解决](./docs/TYPE_INFERENCE_FIX.md)
|
package/dist/App.js
CHANGED
package/dist/core/Api.d.ts
CHANGED
|
@@ -1,43 +1,14 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ModelNames 接口(由业务层扩展以提供代码补全和类型推断)
|
|
3
|
-
* @example
|
|
4
|
-
* ```typescript
|
|
5
|
-
* // 在 .d.ts 文件中扩展
|
|
6
|
-
* interface ModelNamesType {
|
|
7
|
-
* readonly User: unique symbol;
|
|
8
|
-
* }
|
|
9
|
-
* ```
|
|
10
|
-
*/
|
|
11
|
-
export interface ModelNamesType extends Record<string, symbol> {
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* ManagerNames 接口(由业务层扩展以提供代码补全和类型推断)
|
|
15
|
-
* @example
|
|
16
|
-
* ```typescript
|
|
17
|
-
* // 在 .d.ts 文件中扩展
|
|
18
|
-
* interface ManagerNamesType {
|
|
19
|
-
* readonly Home: unique symbol;
|
|
20
|
-
* }
|
|
21
|
-
* ```
|
|
22
|
-
*/
|
|
23
|
-
export interface ManagerNamesType extends Record<string, symbol> {
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* ViewNames 接口(由业务层扩展以提供代码补全和类型推断)
|
|
27
|
-
*/
|
|
28
|
-
export interface ViewNamesType extends Record<string, symbol> {
|
|
29
|
-
}
|
|
30
1
|
/**
|
|
31
2
|
* 核心接口 - 管理 Model 和 Manager 的生命周期
|
|
32
3
|
*
|
|
33
4
|
* 类型推断由业务层的 .d.ts 文件通过函数重载提供
|
|
34
5
|
*/
|
|
35
6
|
export interface ICore {
|
|
36
|
-
/** 注册 Model - 通过
|
|
37
|
-
regModel(
|
|
7
|
+
/** 注册 Model - 通过 Key 自动实例化 */
|
|
8
|
+
regModel(modelKey: string): void;
|
|
38
9
|
/**
|
|
39
10
|
* 获取 Model 实例
|
|
40
|
-
* @param
|
|
11
|
+
* @param modelKey Model 的 Key,使用 ModelNames.XXX
|
|
41
12
|
* @returns Model 实例(具体类型由 .d.ts 文件的函数重载推断)
|
|
42
13
|
* @example
|
|
43
14
|
* ```typescript
|
|
@@ -45,12 +16,12 @@ export interface ICore {
|
|
|
45
16
|
* const userModel = core.getModel(ModelNames.User);
|
|
46
17
|
* ```
|
|
47
18
|
*/
|
|
48
|
-
getModel(
|
|
49
|
-
/** 注册 Manager - 通过
|
|
50
|
-
regManager(
|
|
19
|
+
getModel(modelKey: string): any;
|
|
20
|
+
/** 注册 Manager - 通过 Key 自动实例化 */
|
|
21
|
+
regManager(managerKey: string): void;
|
|
51
22
|
/**
|
|
52
23
|
* 获取 Manager 实例
|
|
53
|
-
* @param
|
|
24
|
+
* @param managerKey Manager 的 Key,使用 ManagerNames.XXX
|
|
54
25
|
* @returns Manager 实例(具体类型由 .d.ts 文件的函数重载推断)
|
|
55
26
|
* @example
|
|
56
27
|
* ```typescript
|
|
@@ -58,7 +29,7 @@ export interface ICore {
|
|
|
58
29
|
* const gameManager = core.getManager(ManagerNames.Game);
|
|
59
30
|
* ```
|
|
60
31
|
*/
|
|
61
|
-
getManager(
|
|
32
|
+
getManager(managerKey: string): any;
|
|
62
33
|
}
|
|
63
34
|
/**
|
|
64
35
|
* Model 基接口 - 数据模型
|
|
@@ -91,14 +62,16 @@ export interface IView {
|
|
|
91
62
|
}
|
|
92
63
|
/**
|
|
93
64
|
* UI 管理器接口 - 管理视图的打开、关闭和栈操作
|
|
65
|
+
*
|
|
66
|
+
* 注意:open 和 openAndPush 的返回类型由 .d.ts 文件的函数重载提供
|
|
94
67
|
*/
|
|
95
68
|
export interface IUIManager {
|
|
96
69
|
/** 打开视图 */
|
|
97
|
-
open
|
|
70
|
+
open(viewKey: string, args?: any): Promise<IView>;
|
|
98
71
|
/** 关闭视图 */
|
|
99
|
-
close(
|
|
72
|
+
close(viewKey: string | IView, destory?: boolean): void;
|
|
100
73
|
/** 打开视图并入栈 */
|
|
101
|
-
openAndPush
|
|
74
|
+
openAndPush(viewKey: string, group: string, args?: any): Promise<IView>;
|
|
102
75
|
/** 关闭栈顶视图并弹出 */
|
|
103
76
|
closeAndPop(group: string, destroy?: boolean): void;
|
|
104
77
|
/** 获取栈顶视图 */
|
package/dist/core/Core.d.ts
CHANGED
|
@@ -3,10 +3,10 @@ export declare abstract class AbstractCore<T extends AbstractCore<T>> implements
|
|
|
3
3
|
private readonly container;
|
|
4
4
|
constructor();
|
|
5
5
|
protected abstract initialize(): void;
|
|
6
|
-
regModel(
|
|
6
|
+
regModel(modelKey: string): void;
|
|
7
7
|
/**
|
|
8
8
|
* 获取 Model 实例
|
|
9
|
-
* @param
|
|
9
|
+
* @param modelKey Model 的 Key,使用 ModelNames.XXX
|
|
10
10
|
* @returns Model 实例(具体类型由 .d.ts 文件的函数重载推断)
|
|
11
11
|
* @example
|
|
12
12
|
* ```typescript
|
|
@@ -14,11 +14,11 @@ export declare abstract class AbstractCore<T extends AbstractCore<T>> implements
|
|
|
14
14
|
* const userModel = core.getModel(ModelNames.User);
|
|
15
15
|
* ```
|
|
16
16
|
*/
|
|
17
|
-
getModel(
|
|
18
|
-
regManager(
|
|
17
|
+
getModel(modelKey: string): any;
|
|
18
|
+
regManager(managerKey: string): void;
|
|
19
19
|
/**
|
|
20
20
|
* 获取 Manager 实例
|
|
21
|
-
* @param
|
|
21
|
+
* @param managerKey Manager 的 Key,使用 ManagerNames.XXX
|
|
22
22
|
* @returns Manager 实例(具体类型由 .d.ts 文件的函数重载推断)
|
|
23
23
|
* @example
|
|
24
24
|
* ```typescript
|
|
@@ -26,21 +26,21 @@ export declare abstract class AbstractCore<T extends AbstractCore<T>> implements
|
|
|
26
26
|
* const gameManager = core.getManager(ManagerNames.Game);
|
|
27
27
|
* ```
|
|
28
28
|
*/
|
|
29
|
-
getManager(
|
|
29
|
+
getManager(managerKey: string): any;
|
|
30
30
|
}
|
|
31
31
|
export declare abstract class AbstractManager implements IManager {
|
|
32
32
|
abstract initialize(): void;
|
|
33
33
|
dispose(): void;
|
|
34
34
|
/**
|
|
35
35
|
* 获取 Model 实例
|
|
36
|
-
* @param
|
|
36
|
+
* @param modelKey Model 的 Key,使用 ModelNames.XXX
|
|
37
37
|
* @returns Model 实例(具体类型由 .d.ts 文件的函数重载推断)
|
|
38
38
|
*/
|
|
39
|
-
protected getModel(
|
|
39
|
+
protected getModel(modelKey: string): any;
|
|
40
40
|
/**
|
|
41
41
|
* 获取 Manager 实例
|
|
42
|
-
* @param
|
|
42
|
+
* @param managerKey Manager 的 Key,使用 ManagerNames.XXX
|
|
43
43
|
* @returns Manager 实例(具体类型由 .d.ts 文件的函数重载推断)
|
|
44
44
|
*/
|
|
45
|
-
protected getManager(
|
|
45
|
+
protected getManager(managerKey: string): any;
|
|
46
46
|
}
|
package/dist/core/Core.js
CHANGED
|
@@ -3,15 +3,15 @@ import { getModelClass, getManagerClass } from './Decorators.js';
|
|
|
3
3
|
|
|
4
4
|
class Container {
|
|
5
5
|
constructor() {
|
|
6
|
-
this.
|
|
6
|
+
this.key2ins = new Map();
|
|
7
7
|
}
|
|
8
|
-
reg(
|
|
9
|
-
this.
|
|
8
|
+
reg(key, ins) {
|
|
9
|
+
this.key2ins.set(key, ins);
|
|
10
10
|
}
|
|
11
|
-
get(
|
|
12
|
-
const ins = this.
|
|
11
|
+
get(key) {
|
|
12
|
+
const ins = this.key2ins.get(key);
|
|
13
13
|
if (!ins)
|
|
14
|
-
throw new Error(`${
|
|
14
|
+
throw new Error(`${key} not registered!`);
|
|
15
15
|
return ins;
|
|
16
16
|
}
|
|
17
17
|
}
|
|
@@ -21,15 +21,15 @@ class AbstractCore {
|
|
|
21
21
|
this.initialize();
|
|
22
22
|
}
|
|
23
23
|
// 注册与获取模型
|
|
24
|
-
regModel(
|
|
25
|
-
const ModelClass = getModelClass(
|
|
24
|
+
regModel(modelKey) {
|
|
25
|
+
const ModelClass = getModelClass(modelKey);
|
|
26
26
|
const model = new ModelClass();
|
|
27
|
-
this.container.reg(
|
|
27
|
+
this.container.reg(modelKey, model);
|
|
28
28
|
model.initialize();
|
|
29
29
|
}
|
|
30
30
|
/**
|
|
31
31
|
* 获取 Model 实例
|
|
32
|
-
* @param
|
|
32
|
+
* @param modelKey Model 的 Key,使用 ModelNames.XXX
|
|
33
33
|
* @returns Model 实例(具体类型由 .d.ts 文件的函数重载推断)
|
|
34
34
|
* @example
|
|
35
35
|
* ```typescript
|
|
@@ -37,19 +37,19 @@ class AbstractCore {
|
|
|
37
37
|
* const userModel = core.getModel(ModelNames.User);
|
|
38
38
|
* ```
|
|
39
39
|
*/
|
|
40
|
-
getModel(
|
|
41
|
-
return this.container.get(
|
|
40
|
+
getModel(modelKey) {
|
|
41
|
+
return this.container.get(modelKey);
|
|
42
42
|
}
|
|
43
43
|
// 注册与获取管理器
|
|
44
|
-
regManager(
|
|
45
|
-
const ManagerClass = getManagerClass(
|
|
44
|
+
regManager(managerKey) {
|
|
45
|
+
const ManagerClass = getManagerClass(managerKey);
|
|
46
46
|
const manager = new ManagerClass();
|
|
47
|
-
this.container.reg(
|
|
47
|
+
this.container.reg(managerKey, manager);
|
|
48
48
|
manager.initialize();
|
|
49
49
|
}
|
|
50
50
|
/**
|
|
51
51
|
* 获取 Manager 实例
|
|
52
|
-
* @param
|
|
52
|
+
* @param managerKey Manager 的 Key,使用 ManagerNames.XXX
|
|
53
53
|
* @returns Manager 实例(具体类型由 .d.ts 文件的函数重载推断)
|
|
54
54
|
* @example
|
|
55
55
|
* ```typescript
|
|
@@ -57,8 +57,8 @@ class AbstractCore {
|
|
|
57
57
|
* const gameManager = core.getManager(ManagerNames.Game);
|
|
58
58
|
* ```
|
|
59
59
|
*/
|
|
60
|
-
getManager(
|
|
61
|
-
return this.container.get(
|
|
60
|
+
getManager(managerKey) {
|
|
61
|
+
return this.container.get(managerKey);
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
class AbstractManager {
|
|
@@ -66,21 +66,21 @@ class AbstractManager {
|
|
|
66
66
|
}
|
|
67
67
|
/**
|
|
68
68
|
* 获取 Model 实例
|
|
69
|
-
* @param
|
|
69
|
+
* @param modelKey Model 的 Key,使用 ModelNames.XXX
|
|
70
70
|
* @returns Model 实例(具体类型由 .d.ts 文件的函数重载推断)
|
|
71
71
|
*/
|
|
72
|
-
getModel(
|
|
72
|
+
getModel(modelKey) {
|
|
73
73
|
// 保持框架独立性,不与具体应用入口(app类)耦合
|
|
74
74
|
// 框架高内聚,使用ServiceLocator获取core
|
|
75
|
-
return ServiceLocator.getService('core').getModel(
|
|
75
|
+
return ServiceLocator.getService('core').getModel(modelKey);
|
|
76
76
|
}
|
|
77
77
|
/**
|
|
78
78
|
* 获取 Manager 实例
|
|
79
|
-
* @param
|
|
79
|
+
* @param managerKey Manager 的 Key,使用 ManagerNames.XXX
|
|
80
80
|
* @returns Manager 实例(具体类型由 .d.ts 文件的函数重载推断)
|
|
81
81
|
*/
|
|
82
|
-
getManager(
|
|
83
|
-
return ServiceLocator.getService('core').getManager(
|
|
82
|
+
getManager(managerKey) {
|
|
83
|
+
return ServiceLocator.getService('core').getManager(managerKey);
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
|
|
@@ -1,10 +1,38 @@
|
|
|
1
|
-
import { ICore
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { ICore } from "./Api";
|
|
2
|
+
/**
|
|
3
|
+
* ModelNames 接口(由业务层扩展以提供代码补全和类型推断)
|
|
4
|
+
* @example
|
|
5
|
+
* ```typescript
|
|
6
|
+
* // 在 .d.ts 文件中扩展
|
|
7
|
+
* interface ModelNamesType {
|
|
8
|
+
* readonly User: 'User';
|
|
9
|
+
* }
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export interface ModelNamesType extends Record<string, string> {
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* ManagerNames 接口(由业务层扩展以提供代码补全和类型推断)
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* // 在 .d.ts 文件中扩展
|
|
19
|
+
* interface ManagerNamesType {
|
|
20
|
+
* readonly Home: 'Home';
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export interface ManagerNamesType extends Record<string, string> {
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* ViewNames 接口(由业务层扩展以提供代码补全和类型推断)
|
|
28
|
+
*/
|
|
29
|
+
export interface ViewNamesType extends Record<string, string> {
|
|
30
|
+
}
|
|
31
|
+
/** Model 名称常量对象,用于代码补全和类型推断 */
|
|
4
32
|
export declare const ModelNames: ModelNamesType;
|
|
5
|
-
/** Manager
|
|
33
|
+
/** Manager 名称常量对象,用于代码补全和类型推断 */
|
|
6
34
|
export declare const ManagerNames: ManagerNamesType;
|
|
7
|
-
/** View
|
|
35
|
+
/** View 名称常量对象,用于代码补全和类型推断 */
|
|
8
36
|
export declare const ViewNames: ViewNamesType;
|
|
9
37
|
/**
|
|
10
38
|
* Model 装饰器,用于注册 Model 到全局注册表
|
|
@@ -27,19 +55,19 @@ export declare function model(name?: string): (ctor: Function) => void;
|
|
|
27
55
|
*/
|
|
28
56
|
export declare function getRegisteredModelNames(): string[];
|
|
29
57
|
/**
|
|
30
|
-
* 通过
|
|
31
|
-
* @param
|
|
58
|
+
* 通过 Key 获取 Model 类构造函数
|
|
59
|
+
* @param modelKey Model 的 Key 标识
|
|
32
60
|
* @returns Model 类构造函数
|
|
33
61
|
* @throws 如果 Model 未注册则抛出错误
|
|
34
62
|
*/
|
|
35
|
-
export declare function getModelClass<T>(
|
|
63
|
+
export declare function getModelClass<T>(modelKey: string): new () => T;
|
|
36
64
|
/**
|
|
37
|
-
* 通过类构造函数获取 Model 的
|
|
65
|
+
* 通过类构造函数获取 Model 的 Key
|
|
38
66
|
* @param ctor Model 类构造函数
|
|
39
|
-
* @returns Model 的
|
|
67
|
+
* @returns Model 的 Key
|
|
40
68
|
* @internal 内部使用
|
|
41
69
|
*/
|
|
42
|
-
export declare function
|
|
70
|
+
export declare function getModelKey(ctor: Function): string | undefined;
|
|
43
71
|
/**
|
|
44
72
|
* Manager 装饰器,用于注册 Manager 到全局注册表
|
|
45
73
|
* @param name 可选的 Manager 名称,如果不提供则使用类名
|
|
@@ -58,19 +86,19 @@ export declare function manager(name?: string): (ctor: Function) => void;
|
|
|
58
86
|
*/
|
|
59
87
|
export declare function getRegisteredManagerNames(): string[];
|
|
60
88
|
/**
|
|
61
|
-
* 通过
|
|
62
|
-
* @param
|
|
89
|
+
* 通过 Key 获取 Manager 类构造函数
|
|
90
|
+
* @param managerKey Manager 的 Key 标识
|
|
63
91
|
* @returns Manager 类构造函数
|
|
64
92
|
* @throws 如果 Manager 未注册则抛出错误
|
|
65
93
|
*/
|
|
66
|
-
export declare function getManagerClass<T>(
|
|
94
|
+
export declare function getManagerClass<T>(managerKey: string): new () => T;
|
|
67
95
|
/**
|
|
68
|
-
* 通过类构造函数获取 Manager 的
|
|
96
|
+
* 通过类构造函数获取 Manager 的 Key
|
|
69
97
|
* @param ctor Manager 类构造函数
|
|
70
|
-
* @returns Manager 的
|
|
98
|
+
* @returns Manager 的 Key
|
|
71
99
|
* @internal 内部使用
|
|
72
100
|
*/
|
|
73
|
-
export declare function
|
|
101
|
+
export declare function getManagerKey(ctor: Function): string | undefined;
|
|
74
102
|
/**
|
|
75
103
|
* View 装饰器,用于注册 View 到全局注册表
|
|
76
104
|
* @param name 可选的 View 名称,如果不提供则使用类名
|
|
@@ -95,12 +123,12 @@ export declare function view(name?: string): (ctor: Function) => void;
|
|
|
95
123
|
*/
|
|
96
124
|
export declare function getRegisteredViewNames(): string[];
|
|
97
125
|
/**
|
|
98
|
-
* 通过
|
|
99
|
-
* @param
|
|
126
|
+
* 通过 Key 获取 View 类构造函数
|
|
127
|
+
* @param viewKey View 的 Key 标识
|
|
100
128
|
* @returns View 类构造函数
|
|
101
129
|
* @throws 如果 View 未注册则抛出错误
|
|
102
130
|
*/
|
|
103
|
-
export declare function getViewClass<T>(
|
|
131
|
+
export declare function getViewClass<T>(viewKey: string): new () => T;
|
|
104
132
|
/**
|
|
105
133
|
* 自动注册所有使用装饰器标记的 Model 和 Manager
|
|
106
134
|
* @param core Core 实例
|
package/dist/core/Decorators.js
CHANGED
|
@@ -1,25 +1,23 @@
|
|
|
1
|
-
import 'reflect-metadata';
|
|
2
|
-
|
|
3
1
|
// ============================================================================
|
|
4
|
-
//
|
|
2
|
+
// Key 注册系统 - Names 对象(提供代码补全和类型推断)
|
|
5
3
|
// ============================================================================
|
|
6
|
-
/** Model
|
|
4
|
+
/** Model 名称常量对象,用于代码补全和类型推断 */
|
|
7
5
|
const ModelNames = {};
|
|
8
|
-
/** Manager
|
|
6
|
+
/** Manager 名称常量对象,用于代码补全和类型推断 */
|
|
9
7
|
const ManagerNames = {};
|
|
10
|
-
/** View
|
|
8
|
+
/** View 名称常量对象,用于代码补全和类型推断 */
|
|
11
9
|
const ViewNames = {};
|
|
12
10
|
// ============================================================================
|
|
13
11
|
// 内部注册表
|
|
14
12
|
// ============================================================================
|
|
15
13
|
// Model 注册表
|
|
16
|
-
const
|
|
17
|
-
const
|
|
14
|
+
const modelRegistry = new Map(); // Key → 类
|
|
15
|
+
const ctorToModelKey = new Map(); // 类 → Key
|
|
18
16
|
// Manager 注册表
|
|
19
|
-
const
|
|
20
|
-
const
|
|
17
|
+
const managerRegistry = new Map(); // Key → 类
|
|
18
|
+
const ctorToManagerKey = new Map(); // 类 → Key
|
|
21
19
|
// View 注册表
|
|
22
|
-
const viewRegistry = new Map(); //
|
|
20
|
+
const viewRegistry = new Map(); // Key → 类
|
|
23
21
|
// ============================================================================
|
|
24
22
|
// Model 装饰器
|
|
25
23
|
// ============================================================================
|
|
@@ -40,11 +38,10 @@ const viewRegistry = new Map(); // Symbol → 类
|
|
|
40
38
|
function model(name) {
|
|
41
39
|
return function (ctor) {
|
|
42
40
|
const modelName = name || ctor.name;
|
|
43
|
-
const modelSymbol = Symbol(modelName);
|
|
44
41
|
// 注册到映射表
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
ModelNames[modelName] =
|
|
42
|
+
modelRegistry.set(modelName, ctor);
|
|
43
|
+
ctorToModelKey.set(ctor, modelName);
|
|
44
|
+
ModelNames[modelName] = modelName;
|
|
48
45
|
console.log(`Model registered: ${modelName}`);
|
|
49
46
|
};
|
|
50
47
|
}
|
|
@@ -56,26 +53,26 @@ function getRegisteredModelNames() {
|
|
|
56
53
|
return Object.keys(ModelNames);
|
|
57
54
|
}
|
|
58
55
|
/**
|
|
59
|
-
* 通过
|
|
60
|
-
* @param
|
|
56
|
+
* 通过 Key 获取 Model 类构造函数
|
|
57
|
+
* @param modelKey Model 的 Key 标识
|
|
61
58
|
* @returns Model 类构造函数
|
|
62
59
|
* @throws 如果 Model 未注册则抛出错误
|
|
63
60
|
*/
|
|
64
|
-
function getModelClass(
|
|
65
|
-
const modelClass =
|
|
61
|
+
function getModelClass(modelKey) {
|
|
62
|
+
const modelClass = modelRegistry.get(modelKey);
|
|
66
63
|
if (!modelClass) {
|
|
67
|
-
throw new Error(`Model not registered
|
|
64
|
+
throw new Error(`Model not registered: ${modelKey}`);
|
|
68
65
|
}
|
|
69
66
|
return modelClass;
|
|
70
67
|
}
|
|
71
68
|
/**
|
|
72
|
-
* 通过类构造函数获取 Model 的
|
|
69
|
+
* 通过类构造函数获取 Model 的 Key
|
|
73
70
|
* @param ctor Model 类构造函数
|
|
74
|
-
* @returns Model 的
|
|
71
|
+
* @returns Model 的 Key
|
|
75
72
|
* @internal 内部使用
|
|
76
73
|
*/
|
|
77
|
-
function
|
|
78
|
-
return
|
|
74
|
+
function getModelKey(ctor) {
|
|
75
|
+
return ctorToModelKey.get(ctor);
|
|
79
76
|
}
|
|
80
77
|
// ============================================================================
|
|
81
78
|
// Manager 装饰器
|
|
@@ -94,11 +91,10 @@ function getModelSymbol(ctor) {
|
|
|
94
91
|
function manager(name) {
|
|
95
92
|
return function (ctor) {
|
|
96
93
|
const managerName = name || ctor.name;
|
|
97
|
-
const managerSymbol = Symbol(managerName);
|
|
98
94
|
// 注册到映射表
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
ManagerNames[managerName] =
|
|
95
|
+
managerRegistry.set(managerName, ctor);
|
|
96
|
+
ctorToManagerKey.set(ctor, managerName);
|
|
97
|
+
ManagerNames[managerName] = managerName;
|
|
102
98
|
console.log(`Manager registered: ${managerName}`);
|
|
103
99
|
};
|
|
104
100
|
}
|
|
@@ -110,26 +106,26 @@ function getRegisteredManagerNames() {
|
|
|
110
106
|
return Object.keys(ManagerNames);
|
|
111
107
|
}
|
|
112
108
|
/**
|
|
113
|
-
* 通过
|
|
114
|
-
* @param
|
|
109
|
+
* 通过 Key 获取 Manager 类构造函数
|
|
110
|
+
* @param managerKey Manager 的 Key 标识
|
|
115
111
|
* @returns Manager 类构造函数
|
|
116
112
|
* @throws 如果 Manager 未注册则抛出错误
|
|
117
113
|
*/
|
|
118
|
-
function getManagerClass(
|
|
119
|
-
const managerClass =
|
|
114
|
+
function getManagerClass(managerKey) {
|
|
115
|
+
const managerClass = managerRegistry.get(managerKey);
|
|
120
116
|
if (!managerClass) {
|
|
121
|
-
throw new Error(`Manager not registered
|
|
117
|
+
throw new Error(`Manager not registered: ${managerKey}`);
|
|
122
118
|
}
|
|
123
119
|
return managerClass;
|
|
124
120
|
}
|
|
125
121
|
/**
|
|
126
|
-
* 通过类构造函数获取 Manager 的
|
|
122
|
+
* 通过类构造函数获取 Manager 的 Key
|
|
127
123
|
* @param ctor Manager 类构造函数
|
|
128
|
-
* @returns Manager 的
|
|
124
|
+
* @returns Manager 的 Key
|
|
129
125
|
* @internal 内部使用
|
|
130
126
|
*/
|
|
131
|
-
function
|
|
132
|
-
return
|
|
127
|
+
function getManagerKey(ctor) {
|
|
128
|
+
return ctorToManagerKey.get(ctor);
|
|
133
129
|
}
|
|
134
130
|
// ============================================================================
|
|
135
131
|
// View 装饰器
|
|
@@ -154,10 +150,9 @@ function getManagerSymbol(ctor) {
|
|
|
154
150
|
function view(name) {
|
|
155
151
|
return function (ctor) {
|
|
156
152
|
const viewName = name || ctor.name;
|
|
157
|
-
const viewSymbol = Symbol(viewName);
|
|
158
153
|
// 注册到映射表
|
|
159
|
-
viewRegistry.set(
|
|
160
|
-
ViewNames[viewName] =
|
|
154
|
+
viewRegistry.set(viewName, ctor);
|
|
155
|
+
ViewNames[viewName] = viewName;
|
|
161
156
|
console.log(`View registered: ${viewName}`);
|
|
162
157
|
};
|
|
163
158
|
}
|
|
@@ -169,15 +164,15 @@ function getRegisteredViewNames() {
|
|
|
169
164
|
return Object.keys(ViewNames);
|
|
170
165
|
}
|
|
171
166
|
/**
|
|
172
|
-
* 通过
|
|
173
|
-
* @param
|
|
167
|
+
* 通过 Key 获取 View 类构造函数
|
|
168
|
+
* @param viewKey View 的 Key 标识
|
|
174
169
|
* @returns View 类构造函数
|
|
175
170
|
* @throws 如果 View 未注册则抛出错误
|
|
176
171
|
*/
|
|
177
|
-
function getViewClass(
|
|
178
|
-
const viewClass = viewRegistry.get(
|
|
172
|
+
function getViewClass(viewKey) {
|
|
173
|
+
const viewClass = viewRegistry.get(viewKey);
|
|
179
174
|
if (!viewClass) {
|
|
180
|
-
throw new Error(`View not registered
|
|
175
|
+
throw new Error(`View not registered: ${viewKey}`);
|
|
181
176
|
}
|
|
182
177
|
return viewClass;
|
|
183
178
|
}
|
|
@@ -199,15 +194,15 @@ function getViewClass(viewSymbol) {
|
|
|
199
194
|
*/
|
|
200
195
|
function autoRegister(core) {
|
|
201
196
|
// 注册所有 Model
|
|
202
|
-
|
|
197
|
+
ctorToModelKey.forEach((modelKey, ctor) => {
|
|
203
198
|
console.log(`${ctor.name} initialize`);
|
|
204
|
-
core.regModel(
|
|
199
|
+
core.regModel(modelKey);
|
|
205
200
|
});
|
|
206
201
|
// 注册所有 Manager
|
|
207
|
-
|
|
202
|
+
ctorToManagerKey.forEach((managerKey, ctor) => {
|
|
208
203
|
console.log(`${ctor.name} initialize`);
|
|
209
|
-
core.regManager(
|
|
204
|
+
core.regManager(managerKey);
|
|
210
205
|
});
|
|
211
206
|
}
|
|
212
207
|
|
|
213
|
-
export { ManagerNames, ModelNames, ViewNames, autoRegister, getManagerClass,
|
|
208
|
+
export { ManagerNames, ModelNames, ViewNames, autoRegister, getManagerClass, getManagerKey, getModelClass, getModelKey, getRegisteredManagerNames, getRegisteredModelNames, getRegisteredViewNames, getViewClass, manager, model, view };
|
package/dist/core/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { AbstractCore, AbstractManager } from './Core.js';
|
|
2
|
-
export { ManagerNames, ModelNames, ViewNames, autoRegister, getManagerClass,
|
|
2
|
+
export { ManagerNames, ModelNames, ViewNames, autoRegister, getManagerClass, getManagerKey, getModelClass, getModelKey, getRegisteredManagerNames, getRegisteredModelNames, getRegisteredViewNames, getViewClass, manager, model, view } from './Decorators.js';
|
|
3
3
|
export { ServiceLocator } from './ServiceLocator.js';
|
package/dist/libs/UIManager.d.ts
CHANGED
|
@@ -3,14 +3,14 @@ import { IUIManager, IView } from "../core";
|
|
|
3
3
|
type ICocosView = IView & Component;
|
|
4
4
|
declare abstract class CcocosUIManager implements IUIManager {
|
|
5
5
|
getTopView(): IView | undefined;
|
|
6
|
-
open
|
|
7
|
-
close(
|
|
8
|
-
openAndPush
|
|
6
|
+
open(viewKey: string, args?: any): Promise<IView>;
|
|
7
|
+
close(viewKey: string | IView, destory?: boolean): void;
|
|
8
|
+
openAndPush(viewKey: string, group: string, args?: any): Promise<IView>;
|
|
9
9
|
closeAndPop(group: string, destroy?: boolean): void;
|
|
10
10
|
clearStack(group: string, destroy?: boolean): void;
|
|
11
|
-
protected abstract internalOpen
|
|
12
|
-
protected abstract internalClose(
|
|
13
|
-
protected abstract internalOpenAndPush
|
|
11
|
+
protected abstract internalOpen(viewKey: string, args?: any): Promise<ICocosView>;
|
|
12
|
+
protected abstract internalClose(viewKey: string | IView, destory?: boolean): void;
|
|
13
|
+
protected abstract internalOpenAndPush(viewKey: string, group: string, args?: any): Promise<ICocosView>;
|
|
14
14
|
protected abstract internalCloseAndPop(group: string, destroy?: boolean): void;
|
|
15
15
|
protected abstract internalClearStack(group: string, destroy?: boolean): void;
|
|
16
16
|
protected abstract internalGetTopView(): ICocosView | undefined;
|
|
@@ -25,9 +25,9 @@ export declare class UIManager extends CcocosUIManager {
|
|
|
25
25
|
private _load;
|
|
26
26
|
private _remove;
|
|
27
27
|
protected internalGetTopView(): ICocosView | undefined;
|
|
28
|
-
protected internalOpen
|
|
29
|
-
protected internalClose(
|
|
30
|
-
protected internalOpenAndPush
|
|
28
|
+
protected internalOpen(viewKey: string, args?: any): Promise<ICocosView>;
|
|
29
|
+
protected internalClose(viewKey: string | IView, destroy?: boolean): void;
|
|
30
|
+
protected internalOpenAndPush(viewKey: string, group: string, args?: any): Promise<ICocosView>;
|
|
31
31
|
protected internalCloseAndPop(group: string, destroy?: boolean): void;
|
|
32
32
|
protected internalClearStack(group: string, destroy?: boolean): void;
|
|
33
33
|
}
|
package/dist/libs/UIManager.js
CHANGED
|
@@ -60,14 +60,14 @@ class CcocosUIManager {
|
|
|
60
60
|
getTopView() {
|
|
61
61
|
return this.internalGetTopView();
|
|
62
62
|
}
|
|
63
|
-
open(
|
|
64
|
-
return this.internalOpen(
|
|
63
|
+
open(viewKey, args) {
|
|
64
|
+
return this.internalOpen(viewKey, args);
|
|
65
65
|
}
|
|
66
|
-
close(
|
|
67
|
-
this.internalClose(
|
|
66
|
+
close(viewKey, destory) {
|
|
67
|
+
this.internalClose(viewKey, destory);
|
|
68
68
|
}
|
|
69
|
-
openAndPush(
|
|
70
|
-
return this.internalOpenAndPush(
|
|
69
|
+
openAndPush(viewKey, group, args) {
|
|
70
|
+
return this.internalOpenAndPush(viewKey, group, args);
|
|
71
71
|
}
|
|
72
72
|
closeAndPop(group, destroy) {
|
|
73
73
|
this.internalCloseAndPop(group, destroy);
|
|
@@ -129,9 +129,9 @@ class UIManager extends CcocosUIManager {
|
|
|
129
129
|
}
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
|
-
_load(
|
|
132
|
+
_load(viewKey, args) {
|
|
133
133
|
return __awaiter(this, void 0, void 0, function* () {
|
|
134
|
-
const viewType = getViewClass(
|
|
134
|
+
const viewType = getViewClass(viewKey);
|
|
135
135
|
let target;
|
|
136
136
|
if (this._cache.has(viewType.name)) {
|
|
137
137
|
target = this._cache.get(viewType.name);
|
|
@@ -147,11 +147,11 @@ class UIManager extends CcocosUIManager {
|
|
|
147
147
|
return target.getComponent(viewType);
|
|
148
148
|
});
|
|
149
149
|
}
|
|
150
|
-
_remove(
|
|
150
|
+
_remove(viewKeyOrInstance, destroy) {
|
|
151
151
|
var _a;
|
|
152
|
-
// 如果是
|
|
153
|
-
if (typeof
|
|
154
|
-
const viewType = getViewClass(
|
|
152
|
+
// 如果是 string,从缓存中获取视图实例
|
|
153
|
+
if (typeof viewKeyOrInstance === 'string') {
|
|
154
|
+
const viewType = getViewClass(viewKeyOrInstance);
|
|
155
155
|
const cached = this._cache.get(viewType.name);
|
|
156
156
|
if (!cached) {
|
|
157
157
|
console.warn(`No cached view found for ${viewType.name}`);
|
|
@@ -166,7 +166,7 @@ class UIManager extends CcocosUIManager {
|
|
|
166
166
|
return;
|
|
167
167
|
}
|
|
168
168
|
// 处理视图实例
|
|
169
|
-
const viewInstance =
|
|
169
|
+
const viewInstance = viewKeyOrInstance;
|
|
170
170
|
if ('__group__' in viewInstance) {
|
|
171
171
|
viewInstance.__group__ = undefined;
|
|
172
172
|
}
|
|
@@ -206,10 +206,10 @@ class UIManager extends CcocosUIManager {
|
|
|
206
206
|
console.warn(`No view found in ${target.name}`);
|
|
207
207
|
return undefined;
|
|
208
208
|
}
|
|
209
|
-
internalOpen(
|
|
209
|
+
internalOpen(viewKey, args) {
|
|
210
210
|
return __awaiter(this, void 0, void 0, function* () {
|
|
211
211
|
this._blockInput(true);
|
|
212
|
-
let view = yield this._load(
|
|
212
|
+
let view = yield this._load(viewKey, args);
|
|
213
213
|
addChild(view.node);
|
|
214
214
|
this._adjustMaskLayer();
|
|
215
215
|
view.onEnter(args);
|
|
@@ -217,14 +217,14 @@ class UIManager extends CcocosUIManager {
|
|
|
217
217
|
return view;
|
|
218
218
|
});
|
|
219
219
|
}
|
|
220
|
-
internalClose(
|
|
221
|
-
this._remove(
|
|
220
|
+
internalClose(viewKey, destroy) {
|
|
221
|
+
this._remove(viewKey, destroy);
|
|
222
222
|
this._adjustMaskLayer();
|
|
223
223
|
}
|
|
224
|
-
internalOpenAndPush(
|
|
224
|
+
internalOpenAndPush(viewKey, group, args) {
|
|
225
225
|
return __awaiter(this, void 0, void 0, function* () {
|
|
226
226
|
this._blockInput(true);
|
|
227
|
-
let view = yield this._load(
|
|
227
|
+
let view = yield this._load(viewKey, args);
|
|
228
228
|
let stack = this._groupStacks.get(group) || [];
|
|
229
229
|
this._groupStacks.set(group, stack);
|
|
230
230
|
let top = stack[stack.length - 1];
|
package/dist/mflow-tools.zip
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dzkcc-mflow",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.34",
|
|
4
4
|
"description": "A modular design and process management framework developed for the cocos engine, suitable for decoupling and dependency injection.",
|
|
5
5
|
"author": "duanzhk",
|
|
6
6
|
"license": "MIT",
|
|
@@ -40,8 +40,5 @@
|
|
|
40
40
|
"rollup-plugin-typescript2": "^0.36.0",
|
|
41
41
|
"typescript": "^4.3.4",
|
|
42
42
|
"unzipper": "^0.12.3"
|
|
43
|
-
},
|
|
44
|
-
"dependencies": {
|
|
45
|
-
"reflect-metadata": "^0.2.2"
|
|
46
43
|
}
|
|
47
44
|
}
|