mm_expand 2.1.0 → 2.1.2
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/lib/base.js +29 -10
- package/package.json +1 -1
package/lib/base.js
CHANGED
|
@@ -26,13 +26,16 @@ class Base extends Event {
|
|
|
26
26
|
*/
|
|
27
27
|
this.status = 'creating';
|
|
28
28
|
|
|
29
|
-
// 初始化监听
|
|
30
|
-
this._initListen();
|
|
31
29
|
// 设置配置
|
|
32
30
|
this.setConfig(config);
|
|
33
31
|
|
|
34
32
|
// 状态变更为 created 已完成
|
|
35
33
|
this.status = 'created';
|
|
34
|
+
|
|
35
|
+
// 监听初始化事件
|
|
36
|
+
this._onInit();
|
|
37
|
+
// 监听销毁事件
|
|
38
|
+
this._onDestroy();
|
|
36
39
|
}
|
|
37
40
|
}
|
|
38
41
|
|
|
@@ -47,23 +50,32 @@ Base.prototype.log = function (level, message, ...params) {
|
|
|
47
50
|
};
|
|
48
51
|
|
|
49
52
|
/**
|
|
50
|
-
*
|
|
53
|
+
* 监听初始化事件
|
|
51
54
|
*/
|
|
52
|
-
Base.prototype.
|
|
53
|
-
let status_last = 'created';
|
|
55
|
+
Base.prototype._onInit = function () {
|
|
54
56
|
// 初始化
|
|
55
|
-
this.on('init:before', (ctx) => {
|
|
57
|
+
this.on('init:before', async (ctx) => {
|
|
56
58
|
this.status = 'initing';
|
|
57
|
-
this._initCore(...ctx.params);
|
|
59
|
+
await this._initCore(...ctx.params);
|
|
58
60
|
});
|
|
59
61
|
this.on('init:after', (ctx) => {
|
|
60
62
|
this.status = 'inited';
|
|
61
63
|
});
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* 监听销毁事件
|
|
68
|
+
*/
|
|
69
|
+
Base.prototype._onDestroy = function () {
|
|
70
|
+
let status_last = 'created';
|
|
62
71
|
// 销毁
|
|
63
|
-
this.on('destroy:before', (ctx) => {
|
|
72
|
+
this.on('destroy:before', async (ctx) => {
|
|
64
73
|
status_last = this.status;
|
|
65
74
|
this.status = 'destroying';
|
|
66
75
|
});
|
|
76
|
+
this.on('destroy:after', async (ctx) => {
|
|
77
|
+
await this._destroyCore(...ctx.params);
|
|
78
|
+
});
|
|
67
79
|
this.on('destroy:success', (ctx) => {
|
|
68
80
|
this.status = 'destroyed';
|
|
69
81
|
});
|
|
@@ -93,7 +105,6 @@ Base.prototype.setConfig = function (config) {
|
|
|
93
105
|
* @returns {object} 返回当前对象
|
|
94
106
|
*/
|
|
95
107
|
Base.prototype._initCore = async function (...params) {
|
|
96
|
-
this.status = 'init';
|
|
97
108
|
return this;
|
|
98
109
|
};
|
|
99
110
|
|
|
@@ -106,11 +117,19 @@ Base.prototype.init = async function (...params) {
|
|
|
106
117
|
return this;
|
|
107
118
|
};
|
|
108
119
|
|
|
120
|
+
/**
|
|
121
|
+
* 销毁核心
|
|
122
|
+
* @returns {object} 返回当前对象
|
|
123
|
+
*/
|
|
124
|
+
Base.prototype._destroyCore = async function () {
|
|
125
|
+
return this;
|
|
126
|
+
};
|
|
127
|
+
|
|
109
128
|
/**
|
|
110
129
|
* 销毁
|
|
111
130
|
*/
|
|
112
131
|
Base.prototype.destroy = async function () {
|
|
113
|
-
|
|
132
|
+
return this;
|
|
114
133
|
};
|
|
115
134
|
|
|
116
135
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mm_expand",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.2",
|
|
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": {
|