mm_tpl 2.5.0 → 2.5.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.
Files changed (2) hide show
  1. package/hook.js +18 -27
  2. package/package.json +2 -2
package/hook.js CHANGED
@@ -27,7 +27,7 @@ Hook.prototype.sort = function (list) {
27
27
  return list.sort((o1, o2) => {
28
28
  return o2.sort - o1.sort
29
29
  });
30
- }
30
+ };
31
31
 
32
32
  /**
33
33
  * 获取函数别名
@@ -46,7 +46,7 @@ Hook.prototype._getName = function (func, alias) {
46
46
  }
47
47
  }
48
48
  return alias;
49
- }
49
+ };
50
50
 
51
51
  /**
52
52
  * 添加函数钩子
@@ -63,14 +63,11 @@ Hook.prototype.addFunc = function (name, func, sort = 100, alias = "") {
63
63
  sort,
64
64
  alias
65
65
  }
66
- var arr = this._func[name];
67
- if (!arr) {
68
- arr = [];
69
- }
66
+ var arr = this._func[name] || [];
70
67
  arr.push(obj);
71
68
  this._func[name] = this.sort(arr);
72
69
  return alias;
73
- }
70
+ };
74
71
 
75
72
  /**
76
73
  * 添加动作钩子
@@ -80,21 +77,18 @@ Hook.prototype.addFunc = function (name, func, sort = 100, alias = "") {
80
77
  * @param {string} alias - 函数别名
81
78
  * @returns {string} 函数别名
82
79
  */
83
- Hook.prototype.addAction = function (name, func, sort, alias) {
80
+ Hook.prototype.addAction = function (name, func, sort = 100, alias = "") {
84
81
  alias = this._getName(func, alias);
85
82
  var obj = {
86
83
  func,
87
84
  sort,
88
85
  alias
89
86
  }
90
- var arr = this._action[name];
91
- if (!arr) {
92
- arr = [];
93
- }
87
+ var arr = this._action[name] || [];
94
88
  arr.push(obj);
95
89
  this._action[name] = this.sort(arr);
96
90
  return alias;
97
- }
91
+ };
98
92
 
99
93
  /**
100
94
  * 添加过滤钩子
@@ -104,21 +98,18 @@ Hook.prototype.addAction = function (name, func, sort, alias) {
104
98
  * @param {string} alias - 函数别名
105
99
  * @returns {string} 函数别名
106
100
  */
107
- Hook.prototype.addFilter = function (name, func, sort, alias) {
101
+ Hook.prototype.addFilter = function (name, func, sort = 100, alias = "") {
108
102
  alias = this._getName(func, alias);
109
103
  var obj = {
110
104
  func,
111
105
  sort,
112
106
  alias
113
107
  }
114
- var arr = this._filter[name];
115
- if (!arr) {
116
- arr = [];
117
- }
108
+ var arr = this._filter[name] || [];
118
109
  arr.push(obj);
119
110
  this._filter[name] = this.sort(arr);
120
111
  return alias;
121
- }
112
+ };
122
113
 
123
114
  /**
124
115
  * 删除函数钩子
@@ -137,7 +128,7 @@ Hook.prototype.delFunc = function (name, alias) {
137
128
  }
138
129
  this._func[name] = list;
139
130
  }
140
- }
131
+ };
141
132
 
142
133
  /**
143
134
  * 删除动作钩子
@@ -156,7 +147,7 @@ Hook.prototype.delAction = function (name, alias) {
156
147
  }
157
148
  this._action[name] = list;
158
149
  }
159
- }
150
+ };
160
151
 
161
152
  /**
162
153
  * 删除过滤钩子
@@ -175,7 +166,7 @@ Hook.prototype.delFilter = function (name, alias = "") {
175
166
  }
176
167
  this._filter[name] = list;
177
168
  }
178
- }
169
+ };
179
170
 
180
171
  /**
181
172
  * 执行函数钩子
@@ -203,7 +194,7 @@ Hook.prototype.runFunc = async function (name, model, req, ...args) {
203
194
  }
204
195
  }
205
196
  return ret;
206
- }
197
+ };
207
198
 
208
199
  /**
209
200
  * 执行动作钩子
@@ -226,7 +217,7 @@ Hook.prototype.runAction = function (name, model, ...args) {
226
217
  }
227
218
  }
228
219
  return ret;
229
- }
220
+ };
230
221
 
231
222
  /**
232
223
  * 执行过滤钩子
@@ -249,7 +240,7 @@ Hook.prototype.runFilter = function (name, model, ret, ...args) {
249
240
  }
250
241
  }
251
242
  return ret;
252
- }
243
+ };
253
244
 
254
245
  /**
255
246
  * 删除钩子
@@ -290,7 +281,7 @@ Hook.prototype.del = function (name, alias) {
290
281
  }
291
282
  this._filter[name] = list;
292
283
  }
293
- }
284
+ };
294
285
 
295
286
  /**
296
287
  * 清空钩子
@@ -306,6 +297,6 @@ Hook.prototype.clear = function (name) {
306
297
  this._action = {};
307
298
  this._filter = {};
308
299
  }
309
- }
300
+ };
310
301
 
311
302
  module.exports = Hook;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mm_tpl",
3
- "version": "2.5.0",
3
+ "version": "2.5.2",
4
4
  "description": "Super Meimei Template Engine - High-performance template engine based on art-template with MVC pattern, hook system, theme switching and caching mechanism",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -34,7 +34,7 @@
34
34
  "homepage": "https://gitee.com/qiuwenwu91/mm_tpl#readme",
35
35
  "dependencies": {
36
36
  "art-template": "^4.13.4",
37
- "mm_expand": "^2.2.8"
37
+ "mm_expand": "^2.2.9"
38
38
  },
39
39
  "engines": {
40
40
  "node": ">=12.0.0"