dzkcc-mflow 0.0.35 → 0.0.36

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.
@@ -33,8 +33,16 @@ export interface ViewNamesType extends Record<string, string> {
33
33
  * 类型推断由业务层的 .d.ts 文件通过函数重载提供
34
34
  */
35
35
  export interface ICore {
36
- /** 注册 Model - 通过 Key 自动实例化 */
37
- regModel<T extends keyof ModelNamesType>(modelKey: T): void;
36
+ /**
37
+ * 注册 Model - 通过 Key 自动实例化
38
+ * @param modelKey Model 的 Key,使用 ModelNames.XXX
39
+ * @example
40
+ * ```typescript
41
+ * // 手动注册(通常不需要,推荐使用 autoRegister)
42
+ * core.regModel(ModelNames.User);
43
+ * ```
44
+ */
45
+ regModel(modelKey: keyof ModelNamesType): void;
38
46
  /**
39
47
  * 获取 Model 实例
40
48
  * @param modelKey Model 的 Key,使用 ModelNames.XXX
@@ -45,9 +53,17 @@ export interface ICore {
45
53
  * const userModel = core.getModel(ModelNames.User);
46
54
  * ```
47
55
  */
48
- getModel<T extends keyof ModelNamesType>(modelKey: T): any;
49
- /** 注册 Manager - 通过 Key 自动实例化 */
50
- regManager<T extends keyof ManagerNamesType>(managerKey: T): void;
56
+ getModel(modelKey: keyof ModelNamesType): any;
57
+ /**
58
+ * 注册 Manager - 通过 Key 自动实例化
59
+ * @param managerKey Manager 的 Key,使用 ManagerNames.XXX
60
+ * @example
61
+ * ```typescript
62
+ * // 手动注册(通常不需要,推荐使用 autoRegister)
63
+ * core.regManager(ManagerNames.Game);
64
+ * ```
65
+ */
66
+ regManager(managerKey: keyof ManagerNamesType): void;
51
67
  /**
52
68
  * 获取 Manager 实例
53
69
  * @param managerKey Manager 的 Key,使用 ManagerNames.XXX
@@ -58,7 +74,19 @@ export interface ICore {
58
74
  * const gameManager = core.getManager(ManagerNames.Game);
59
75
  * ```
60
76
  */
61
- getManager<T extends keyof ManagerNamesType>(managerKey: T): any;
77
+ getManager(managerKey: keyof ManagerNamesType): any;
78
+ /**
79
+ * 检查 Model 是否已注册
80
+ * @param modelKey Model 的 Key
81
+ * @returns 是否已注册
82
+ */
83
+ hasModel(modelKey: keyof ModelNamesType): boolean;
84
+ /**
85
+ * 检查 Manager 是否已注册
86
+ * @param managerKey Manager 的 Key
87
+ * @returns 是否已注册
88
+ */
89
+ hasManager(managerKey: keyof ManagerNamesType): boolean;
62
90
  }
63
91
  /**
64
92
  * Model 基接口 - 数据模型
@@ -96,11 +124,11 @@ export interface IView {
96
124
  */
97
125
  export interface IUIManager {
98
126
  /** 打开视图 */
99
- open<T extends keyof ViewNamesType>(viewKey: T, args?: any): Promise<IView>;
127
+ open(viewKey: keyof ViewNamesType, args?: any): Promise<IView>;
100
128
  /** 关闭视图 */
101
- close<T extends keyof ViewNamesType>(viewKey: T | IView, destory?: boolean): void;
129
+ close(viewKey: keyof ViewNamesType | IView, destory?: boolean): void;
102
130
  /** 打开视图并入栈 */
103
- openAndPush<T extends keyof ViewNamesType>(viewKey: T, group: string, args?: any): Promise<IView>;
131
+ openAndPush(viewKey: keyof ViewNamesType, group: string, args?: any): Promise<IView>;
104
132
  /** 关闭栈顶视图并弹出 */
105
133
  closeAndPop(group: string, destroy?: boolean): void;
106
134
  /** 获取栈顶视图 */
@@ -3,7 +3,7 @@ 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<T extends keyof ModelNamesType>(modelKey: T): void;
6
+ regModel(modelKey: keyof ModelNamesType): void;
7
7
  /**
8
8
  * 获取 Model 实例
9
9
  * @param modelKey Model 的 Key,使用 ModelNames.XXX
@@ -14,8 +14,8 @@ export declare abstract class AbstractCore<T extends AbstractCore<T>> implements
14
14
  * const userModel = core.getModel(ModelNames.User);
15
15
  * ```
16
16
  */
17
- getModel<T extends keyof ModelNamesType>(modelKey: T): any;
18
- regManager<T extends keyof ManagerNamesType>(managerKey: T): void;
17
+ getModel(modelKey: keyof ModelNamesType): any;
18
+ regManager(managerKey: keyof ManagerNamesType): void;
19
19
  /**
20
20
  * 获取 Manager 实例
21
21
  * @param managerKey Manager 的 Key,使用 ManagerNames.XXX
@@ -26,7 +26,19 @@ export declare abstract class AbstractCore<T extends AbstractCore<T>> implements
26
26
  * const gameManager = core.getManager(ManagerNames.Game);
27
27
  * ```
28
28
  */
29
- getManager<T extends keyof ManagerNamesType>(managerKey: T): any;
29
+ getManager(managerKey: keyof ManagerNamesType): any;
30
+ /**
31
+ * 检查 Model 是否已注册
32
+ * @param modelKey Model 的 Key
33
+ * @returns 是否已注册
34
+ */
35
+ hasModel(modelKey: keyof ModelNamesType): boolean;
36
+ /**
37
+ * 检查 Manager 是否已注册
38
+ * @param managerKey Manager 的 Key
39
+ * @returns 是否已注册
40
+ */
41
+ hasManager(managerKey: keyof ManagerNamesType): boolean;
30
42
  }
31
43
  export declare abstract class AbstractManager implements IManager {
32
44
  abstract initialize(): void;
@@ -36,11 +48,11 @@ export declare abstract class AbstractManager implements IManager {
36
48
  * @param modelKey Model 的 Key,使用 ModelNames.XXX
37
49
  * @returns Model 实例(具体类型由 .d.ts 文件的函数重载推断)
38
50
  */
39
- protected getModel<T extends keyof ModelNamesType>(modelKey: T): any;
51
+ protected getModel(modelKey: keyof ModelNamesType): any;
40
52
  /**
41
53
  * 获取 Manager 实例
42
54
  * @param managerKey Manager 的 Key,使用 ManagerNames.XXX
43
55
  * @returns Manager 实例(具体类型由 .d.ts 文件的函数重载推断)
44
56
  */
45
- protected getManager<T extends keyof ManagerNamesType>(managerKey: T): any;
57
+ protected getManager(managerKey: keyof ManagerNamesType): any;
46
58
  }
package/dist/core/Core.js CHANGED
@@ -14,6 +14,9 @@ class Container {
14
14
  throw new Error(`${key} not registered!`);
15
15
  return ins;
16
16
  }
17
+ has(key) {
18
+ return this.key2ins.has(key);
19
+ }
17
20
  }
18
21
  class AbstractCore {
19
22
  constructor() {
@@ -62,6 +65,22 @@ class AbstractCore {
62
65
  getManager(managerKey) {
63
66
  return this.container.get(managerKey);
64
67
  }
68
+ /**
69
+ * 检查 Model 是否已注册
70
+ * @param modelKey Model 的 Key
71
+ * @returns 是否已注册
72
+ */
73
+ hasModel(modelKey) {
74
+ return this.container.has(modelKey);
75
+ }
76
+ /**
77
+ * 检查 Manager 是否已注册
78
+ * @param managerKey Manager 的 Key
79
+ * @returns 是否已注册
80
+ */
81
+ hasManager(managerKey) {
82
+ return this.container.has(managerKey);
83
+ }
65
84
  }
66
85
  class AbstractManager {
67
86
  dispose() {
@@ -103,6 +103,7 @@ export declare function getViewClass<T>(viewKey: string): new () => T;
103
103
  /**
104
104
  * 自动注册所有使用装饰器标记的 Model 和 Manager
105
105
  * @param core Core 实例
106
+ * @param options 注册选项
106
107
  * @example
107
108
  * ```typescript
108
109
  * // 导入所有 Model 和 Manager
@@ -111,6 +112,15 @@ export declare function getViewClass<T>(viewKey: string): new () => T;
111
112
  *
112
113
  * // 自动注册
113
114
  * autoRegister(mf.core);
115
+ *
116
+ * // 带选项的自动注册
117
+ * autoRegister(mf.core, {
118
+ * skipExisting: true, // 跳过已注册的
119
+ * verbose: false // 静默模式
120
+ * });
114
121
  * ```
115
122
  */
116
- export declare function autoRegister(core: ICore): void;
123
+ export declare function autoRegister(core: ICore, options?: {
124
+ skipExisting?: boolean;
125
+ verbose?: boolean;
126
+ }): void;
@@ -182,6 +182,7 @@ function getViewClass(viewKey) {
182
182
  /**
183
183
  * 自动注册所有使用装饰器标记的 Model 和 Manager
184
184
  * @param core Core 实例
185
+ * @param options 注册选项
185
186
  * @example
186
187
  * ```typescript
187
188
  * // 导入所有 Model 和 Manager
@@ -190,17 +191,36 @@ function getViewClass(viewKey) {
190
191
  *
191
192
  * // 自动注册
192
193
  * autoRegister(mf.core);
194
+ *
195
+ * // 带选项的自动注册
196
+ * autoRegister(mf.core, {
197
+ * skipExisting: true, // 跳过已注册的
198
+ * verbose: false // 静默模式
199
+ * });
193
200
  * ```
194
201
  */
195
- function autoRegister(core) {
202
+ function autoRegister(core, options = {}) {
203
+ const { skipExisting = false, verbose = true } = options;
196
204
  // 注册所有 Model
197
205
  ctorToModelKey.forEach((modelKey, ctor) => {
198
- console.log(`${ctor.name} initialize`);
206
+ if (skipExisting && core.hasModel(modelKey)) {
207
+ if (verbose)
208
+ console.log(`${ctor.name} already registered, skipping`);
209
+ return;
210
+ }
211
+ if (verbose)
212
+ console.log(`${ctor.name} initialize`);
199
213
  core.regModel(modelKey);
200
214
  });
201
215
  // 注册所有 Manager
202
216
  ctorToManagerKey.forEach((managerKey, ctor) => {
203
- console.log(`${ctor.name} initialize`);
217
+ if (skipExisting && core.hasManager(managerKey)) {
218
+ if (verbose)
219
+ console.log(`${ctor.name} already registered, skipping`);
220
+ return;
221
+ }
222
+ if (verbose)
223
+ console.log(`${ctor.name} initialize`);
204
224
  core.regManager(managerKey);
205
225
  });
206
226
  }
@@ -4,9 +4,9 @@ import { ViewNamesType } from "../core";
4
4
  type ICocosView = IView & Component;
5
5
  declare abstract class CcocosUIManager implements IUIManager {
6
6
  getTopView(): IView | undefined;
7
- open<T extends keyof ViewNamesType>(viewKey: T, args?: any): Promise<IView>;
8
- close<T extends keyof ViewNamesType>(viewKey: T | IView, destory?: boolean): void;
9
- openAndPush<T extends keyof ViewNamesType>(viewKey: T, group: string, args?: any): Promise<IView>;
7
+ open(viewKey: keyof ViewNamesType, args?: any): Promise<IView>;
8
+ close(viewKey: keyof ViewNamesType | IView, destory?: boolean): void;
9
+ openAndPush(viewKey: keyof ViewNamesType, group: string, args?: any): Promise<IView>;
10
10
  closeAndPop(group: string, destroy?: boolean): void;
11
11
  clearStack(group: string, destroy?: boolean): void;
12
12
  protected abstract internalOpen(viewKey: string, args?: any): Promise<ICocosView>;
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dzkcc-mflow",
3
- "version": "0.0.35",
3
+ "version": "0.0.36",
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",