dzkcc-mflow 0.0.34 → 0.0.35

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.
@@ -1,3 +1,32 @@
1
+ /**
2
+ * ModelNames 接口(由业务层扩展以提供代码补全和类型推断)
3
+ * @example
4
+ * ```typescript
5
+ * // 在 .d.ts 文件中扩展
6
+ * interface ModelNamesType {
7
+ * readonly User: 'User';
8
+ * }
9
+ * ```
10
+ */
11
+ export interface ModelNamesType extends Record<string, string> {
12
+ }
13
+ /**
14
+ * ManagerNames 接口(由业务层扩展以提供代码补全和类型推断)
15
+ * @example
16
+ * ```typescript
17
+ * // 在 .d.ts 文件中扩展
18
+ * interface ManagerNamesType {
19
+ * readonly Home: 'Home';
20
+ * }
21
+ * ```
22
+ */
23
+ export interface ManagerNamesType extends Record<string, string> {
24
+ }
25
+ /**
26
+ * ViewNames 接口(由业务层扩展以提供代码补全和类型推断)
27
+ */
28
+ export interface ViewNamesType extends Record<string, string> {
29
+ }
1
30
  /**
2
31
  * 核心接口 - 管理 Model 和 Manager 的生命周期
3
32
  *
@@ -5,7 +34,7 @@
5
34
  */
6
35
  export interface ICore {
7
36
  /** 注册 Model - 通过 Key 自动实例化 */
8
- regModel(modelKey: string): void;
37
+ regModel<T extends keyof ModelNamesType>(modelKey: T): void;
9
38
  /**
10
39
  * 获取 Model 实例
11
40
  * @param modelKey Model 的 Key,使用 ModelNames.XXX
@@ -16,9 +45,9 @@ export interface ICore {
16
45
  * const userModel = core.getModel(ModelNames.User);
17
46
  * ```
18
47
  */
19
- getModel(modelKey: string): any;
48
+ getModel<T extends keyof ModelNamesType>(modelKey: T): any;
20
49
  /** 注册 Manager - 通过 Key 自动实例化 */
21
- regManager(managerKey: string): void;
50
+ regManager<T extends keyof ManagerNamesType>(managerKey: T): void;
22
51
  /**
23
52
  * 获取 Manager 实例
24
53
  * @param managerKey Manager 的 Key,使用 ManagerNames.XXX
@@ -29,7 +58,7 @@ export interface ICore {
29
58
  * const gameManager = core.getManager(ManagerNames.Game);
30
59
  * ```
31
60
  */
32
- getManager(managerKey: string): any;
61
+ getManager<T extends keyof ManagerNamesType>(managerKey: T): any;
33
62
  }
34
63
  /**
35
64
  * Model 基接口 - 数据模型
@@ -67,11 +96,11 @@ export interface IView {
67
96
  */
68
97
  export interface IUIManager {
69
98
  /** 打开视图 */
70
- open(viewKey: string, args?: any): Promise<IView>;
99
+ open<T extends keyof ViewNamesType>(viewKey: T, args?: any): Promise<IView>;
71
100
  /** 关闭视图 */
72
- close(viewKey: string | IView, destory?: boolean): void;
101
+ close<T extends keyof ViewNamesType>(viewKey: T | IView, destory?: boolean): void;
73
102
  /** 打开视图并入栈 */
74
- openAndPush(viewKey: string, group: string, args?: any): Promise<IView>;
103
+ openAndPush<T extends keyof ViewNamesType>(viewKey: T, group: string, args?: any): Promise<IView>;
75
104
  /** 关闭栈顶视图并弹出 */
76
105
  closeAndPop(group: string, destroy?: boolean): void;
77
106
  /** 获取栈顶视图 */
@@ -1,9 +1,9 @@
1
- import { ICore, IManager } from "./Api";
1
+ import { ICore, IManager, ModelNamesType, ManagerNamesType } from "./Api";
2
2
  export declare abstract class AbstractCore<T extends AbstractCore<T>> implements ICore {
3
3
  private readonly container;
4
4
  constructor();
5
5
  protected abstract initialize(): void;
6
- regModel(modelKey: string): void;
6
+ regModel<T extends keyof ModelNamesType>(modelKey: T): 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(modelKey: string): any;
18
- regManager(managerKey: string): void;
17
+ getModel<T extends keyof ModelNamesType>(modelKey: T): any;
18
+ regManager<T extends keyof ManagerNamesType>(managerKey: T): void;
19
19
  /**
20
20
  * 获取 Manager 实例
21
21
  * @param managerKey Manager 的 Key,使用 ManagerNames.XXX
@@ -26,7 +26,7 @@ export declare abstract class AbstractCore<T extends AbstractCore<T>> implements
26
26
  * const gameManager = core.getManager(ManagerNames.Game);
27
27
  * ```
28
28
  */
29
- getManager(managerKey: string): any;
29
+ getManager<T extends keyof ManagerNamesType>(managerKey: T): any;
30
30
  }
31
31
  export declare abstract class AbstractManager implements IManager {
32
32
  abstract initialize(): void;
@@ -36,11 +36,11 @@ export declare abstract class AbstractManager implements IManager {
36
36
  * @param modelKey Model 的 Key,使用 ModelNames.XXX
37
37
  * @returns Model 实例(具体类型由 .d.ts 文件的函数重载推断)
38
38
  */
39
- protected getModel(modelKey: string): any;
39
+ protected getModel<T extends keyof ModelNamesType>(modelKey: T): any;
40
40
  /**
41
41
  * 获取 Manager 实例
42
42
  * @param managerKey Manager 的 Key,使用 ManagerNames.XXX
43
43
  * @returns Manager 实例(具体类型由 .d.ts 文件的函数重载推断)
44
44
  */
45
- protected getManager(managerKey: string): any;
45
+ protected getManager<T extends keyof ManagerNamesType>(managerKey: T): any;
46
46
  }
package/dist/core/Core.js CHANGED
@@ -22,9 +22,10 @@ class AbstractCore {
22
22
  }
23
23
  // 注册与获取模型
24
24
  regModel(modelKey) {
25
- const ModelClass = getModelClass(modelKey);
25
+ const modelKeyStr = modelKey;
26
+ const ModelClass = getModelClass(modelKeyStr);
26
27
  const model = new ModelClass();
27
- this.container.reg(modelKey, model);
28
+ this.container.reg(modelKeyStr, model);
28
29
  model.initialize();
29
30
  }
30
31
  /**
@@ -42,9 +43,10 @@ class AbstractCore {
42
43
  }
43
44
  // 注册与获取管理器
44
45
  regManager(managerKey) {
45
- const ManagerClass = getManagerClass(managerKey);
46
+ const managerKeyStr = managerKey;
47
+ const ManagerClass = getManagerClass(managerKeyStr);
46
48
  const manager = new ManagerClass();
47
- this.container.reg(managerKey, manager);
49
+ this.container.reg(managerKeyStr, manager);
48
50
  manager.initialize();
49
51
  }
50
52
  /**
@@ -1,33 +1,4 @@
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
- }
1
+ import { ICore, ModelNamesType, ManagerNamesType, ViewNamesType } from "./Api";
31
2
  /** Model 名称常量对象,用于代码补全和类型推断 */
32
3
  export declare const ModelNames: ModelNamesType;
33
4
  /** Manager 名称常量对象,用于代码补全和类型推断 */
@@ -1,5 +1,6 @@
1
1
  import { Component } from 'cc';
2
- import { IView, IManager, IModel, IEventManager, ICocosResManager } from '../core';
2
+ import { IView, IEventManager, ICocosResManager } from '../core';
3
+ import { ModelNamesType, ManagerNamesType } from '../core';
3
4
  export declare abstract class BaseView extends Component implements IView {
4
5
  /** @internal */
5
6
  private readonly __isIView__;
@@ -16,6 +17,26 @@ export declare abstract class BaseView extends Component implements IView {
16
17
  abstract onEnter(args?: any): void;
17
18
  onExit(): void;
18
19
  protected onDestroy(): void;
19
- protected getManager<T extends IManager>(managerSymbol: symbol): T;
20
- protected getModel<T extends IModel>(modelSymbol: symbol): T;
20
+ /**
21
+ * 获取 Model 实例
22
+ * @param modelKey Model 的 Key,使用 ModelNames.XXX
23
+ * @returns Model 实例(具体类型由 .d.ts 文件的函数重载推断)
24
+ * @example
25
+ * ```typescript
26
+ * // 类型由 .d.ts 文件的重载自动推断
27
+ * const userModel = this.getModel(ModelNames.User);
28
+ * ```
29
+ */
30
+ protected getModel<T extends keyof ModelNamesType>(modelKey: T): any;
31
+ /**
32
+ * 获取 Manager 实例
33
+ * @param managerKey Manager 的 Key,使用 ManagerNames.XXX
34
+ * @returns Manager 实例(具体类型由 .d.ts 文件的函数重载推断)
35
+ * @example
36
+ * ```typescript
37
+ * // 类型由 .d.ts 文件的重载自动推断
38
+ * const gameManager = this.getManager(ManagerNames.Game);
39
+ * ```
40
+ */
41
+ protected getManager<T extends keyof ManagerNamesType>(managerKey: T): any;
21
42
  }
@@ -69,13 +69,31 @@ class BaseView extends Component {
69
69
  });
70
70
  this._loaderHandlers = [];
71
71
  }
72
- getManager(managerSymbol) {
73
- // 业务组件避免直接依赖底层服务定位器,所以使用app.core统一对外接口,方便后续架构演进
74
- return mf.core.getManager(managerSymbol);
72
+ /**
73
+ * 获取 Model 实例
74
+ * @param modelKey Model 的 Key,使用 ModelNames.XXX
75
+ * @returns Model 实例(具体类型由 .d.ts 文件的函数重载推断)
76
+ * @example
77
+ * ```typescript
78
+ * // 类型由 .d.ts 文件的重载自动推断
79
+ * const userModel = this.getModel(ModelNames.User);
80
+ * ```
81
+ */
82
+ getModel(modelKey) {
83
+ return mf.core.getModel(modelKey);
75
84
  }
76
- getModel(modelSymbol) {
77
- // 业务组件避免直接依赖底层服务定位器,所以使用app.core统一对外接口,方便后续架构演进
78
- return mf.core.getModel(modelSymbol);
85
+ /**
86
+ * 获取 Manager 实例
87
+ * @param managerKey Manager 的 Key,使用 ManagerNames.XXX
88
+ * @returns Manager 实例(具体类型由 .d.ts 文件的函数重载推断)
89
+ * @example
90
+ * ```typescript
91
+ * // 类型由 .d.ts 文件的重载自动推断
92
+ * const gameManager = this.getManager(ManagerNames.Game);
93
+ * ```
94
+ */
95
+ getManager(managerKey) {
96
+ return mf.core.getManager(managerKey);
79
97
  }
80
98
  }
81
99
 
@@ -1,11 +1,12 @@
1
1
  import { Component } from "cc";
2
2
  import { IUIManager, IView } from "../core";
3
+ import { ViewNamesType } from "../core";
3
4
  type ICocosView = IView & Component;
4
5
  declare abstract class CcocosUIManager implements IUIManager {
5
6
  getTopView(): IView | undefined;
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>;
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>;
9
10
  closeAndPop(group: string, destroy?: boolean): void;
10
11
  clearStack(group: string, destroy?: boolean): void;
11
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.34",
3
+ "version": "0.0.35",
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",