mm_expand 2.0.4 → 2.0.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.
Files changed (3) hide show
  1. package/lib/base.js +15 -118
  2. package/lib/event.js +4 -0
  3. package/package.json +1 -1
package/lib/base.js CHANGED
@@ -8,41 +8,24 @@ require('./global');
8
8
  * 基础类
9
9
  */
10
10
  class Base extends Event {
11
- static config = {
12
- // 模块名称
13
- name: '',
14
- // 模块标题
15
- title: '',
16
- // 模块描述
17
- description: '',
18
- // 状态, 可选值: 1-启用, 0-禁用
19
- state: 1
20
- };
21
-
22
11
  /**
23
12
  * 构造函数
24
13
  * @param {object} config 配置参数
25
- * @param {object} parent 父模块
26
14
  */
27
- constructor(config, parent = null) {
28
- super();
29
- /**
30
- * 配置参数
31
- * @type {object}
32
- */
33
- this.config = { ...this.constructor.config };
34
-
15
+ constructor(config) {
16
+ super(config);
35
17
  /**
36
18
  * 状态
37
19
  * @type {string} - 状态, 可选值: creating, created, initing, inited, loading, loaded, starting, running, stopping, stopped, unloading, unloaded, destroying, destroyed
38
20
  */
39
21
  this.status = 'creating';
40
22
 
41
- // 设置配置
42
- this.setConfig(config);
43
23
  // 初始化监听
44
24
  this._initListen();
45
-
25
+ // 设置配置
26
+ this.setConfig(config);
27
+
28
+ // 状态变更为 created 已完成
46
29
  this.status = 'created';
47
30
  }
48
31
  }
@@ -54,7 +37,7 @@ class Base extends Event {
54
37
  * @param {...any} params 日志参数
55
38
  */
56
39
  Base.prototype.log = function (level, message, ...params) {
57
- this._logger[level](`[${this.constructor.name}] [${this.config.name}] ${message}`, ...params);
40
+ this._logger[level](`[${this.constructor.name}] ${message}`, ...params);
58
41
  };
59
42
 
60
43
  /**
@@ -70,55 +53,11 @@ Base.prototype._initListen = function () {
70
53
  this.on('init:after', (ctx) => {
71
54
  this.status = 'inited';
72
55
  });
73
- // 加载
74
- this.on('load:before', (ctx) => {
75
- status_last = this.status;
76
- this.status = 'loading';
77
- });
78
- this.on('load:after', (ctx) => {
79
- this.status = 'loaded';
80
- });
81
- // 启动
82
- this.on('start:before', (ctx) => {
83
- status_last = this.status;
84
- this.status = 'starting';
85
- });
86
- this.on('start:success', (ctx) => {
87
- this.status = 'running';
88
- });
89
- this.on('start:error', (ctx) => {
90
- this.status = status_last;
91
- });
92
- // 停止
93
- this.on('stop:before', (ctx) => {
94
- status_last = this.status;
95
- this.status = 'stopping';
96
- });
97
- this.on('stop:success', (ctx) => {
98
- this.status = 'stopped';
99
- });
100
- this.on('stop:error', (ctx) => {
101
- this.status = status_last;
102
- });
103
- // 卸载
104
- this.on('unload:before', (ctx) => {
105
- status_last = this.status;
106
- this.status = 'unloading';
107
- });
108
- this.on('unload:after', (ctx) => {
109
- this.status = 'unloaded';
110
- });
111
56
  // 销毁
112
57
  this.on('destroy:before', (ctx) => {
113
58
  status_last = this.status;
114
59
  this.status = 'destroying';
115
60
  });
116
- this.on('destroy:check', (ctx) => {
117
- if (status_last !== 'stopped') {
118
- status_last = this.status;
119
- ctx.error = new Error('销毁前必须先停止');
120
- }
121
- });
122
61
  this.on('destroy:success', (ctx) => {
123
62
  this.status = 'destroyed';
124
63
  });
@@ -158,20 +97,6 @@ Base.prototype.init = async function (...params) {
158
97
  return this;
159
98
  };
160
99
 
161
- /**
162
- * 启动
163
- */
164
- Base.prototype.start = async function () {
165
-
166
- };
167
-
168
- /**
169
- * 停止
170
- */
171
- Base.prototype.stop = async function () {
172
-
173
- };
174
-
175
100
  /**
176
101
  * 销毁
177
102
  */
@@ -179,31 +104,6 @@ Base.prototype.destroy = async function () {
179
104
 
180
105
  };
181
106
 
182
- /**
183
- * 重启
184
- */
185
- Base.prototype.restart = async function () {
186
- await this.do('stop');
187
- await this.do('start');
188
- };
189
-
190
- /**
191
- * 是否运行中
192
- * @returns {boolean} 是否运行中
193
- */
194
- Base.prototype.isRunning = function () {
195
- return this.status === 'running';
196
- };
197
-
198
- /**
199
- * 结束
200
- */
201
- Base.prototype.end = async function () {
202
- await this.do('stop');
203
- await this.do('destroy');
204
- };
205
-
206
-
207
107
  /**
208
108
  * 事件驱动
209
109
  * @param {string} method 方法名称
@@ -246,22 +146,19 @@ Base.prototype._do = async function (method, ...params) {
246
146
  }
247
147
 
248
148
  await this._doExecuteMethod(method, ctx);
249
-
250
- // 如果执行成功,进行成功处理
251
- if (!ctx.error) {
252
- await this._doSuccessProcess(method, ctx);
253
- }
254
-
255
- // return ctx.result;
256
149
  } catch (error) {
257
150
  ctx.error = error;
258
-
151
+ }
152
+ if (ctx.error) {
259
153
  // 执行错误处理
260
154
  await this._doErrorProcess(method, ctx);
261
- } finally {
262
- // 无论成功失败,都要执行后处理
263
- await this._doAfterProcess(method, ctx);
264
155
  }
156
+ else {
157
+ // 如果执行成功,进行成功处理
158
+ await this._doSuccessProcess(method, ctx);
159
+ }
160
+ // 无论成功失败,都要执行后处理
161
+ await this._doAfterProcess(method, ctx);
265
162
  return ctx;
266
163
  };
267
164
 
package/lib/event.js CHANGED
@@ -16,6 +16,10 @@ class Event {
16
16
  * @param {object} config 配置参数
17
17
  */
18
18
  constructor(config) {
19
+ /**
20
+ * 配置参数
21
+ * @type {object} - 配置参数
22
+ */
19
23
  this.config = {
20
24
  ...Event.config,
21
25
  ...config || {}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mm_expand",
3
- "version": "2.0.4",
3
+ "version": "2.0.5",
4
4
  "description": "Super Meimei Prototype Function Extension Module - Enhanced operations for string, array, object, date manipulation with error prevention and simplified business logic.",
5
5
  "main": "index.js",
6
6
  "scripts": {