mm_tpl 2.1.8 → 2.1.9
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/hook.js +7 -5
- package/index.js +1 -1
- package/package.json +1 -1
- package/template/game/bar.html +1 -1
- package/test.js +5 -5
package/hook.js
CHANGED
|
@@ -88,16 +88,17 @@ Hook.prototype.delFilter = function(name, alias = "") {
|
|
|
88
88
|
/**
|
|
89
89
|
* 运行动作钩子
|
|
90
90
|
* @param {String} name 钩子名称
|
|
91
|
-
* @param {Object}
|
|
91
|
+
* @param {Object} model 模型
|
|
92
92
|
* @param {Object} args 附加参数
|
|
93
93
|
*/
|
|
94
|
-
Hook.prototype.runAction = function(name,
|
|
94
|
+
Hook.prototype.runAction = function(name, model, ...args) {
|
|
95
|
+
var ret = "";
|
|
95
96
|
var dict = this.dict_action;
|
|
96
97
|
var list = dict[name];
|
|
97
98
|
if (list) {
|
|
98
99
|
for (var i = 0; i < list.length; i++) {
|
|
99
100
|
var o = list[i];
|
|
100
|
-
ret += o.func(
|
|
101
|
+
ret += o.func(model, ...args);
|
|
101
102
|
}
|
|
102
103
|
}
|
|
103
104
|
return ret;
|
|
@@ -107,15 +108,16 @@ Hook.prototype.runAction = function(name, ret, ...args) {
|
|
|
107
108
|
* 运行过滤钩子
|
|
108
109
|
* @param {String} name 钩子名称
|
|
109
110
|
* @param {Object} ret 结果
|
|
111
|
+
* @param {Object} model 模型
|
|
110
112
|
* @param {Object} args 附加参数
|
|
111
113
|
*/
|
|
112
|
-
Hook.prototype.runFilter = function(name, ret, ...args) {
|
|
114
|
+
Hook.prototype.runFilter = function(name, ret, model, ...args) {
|
|
113
115
|
var dict = this.dict_filter;
|
|
114
116
|
var list = dict[name];
|
|
115
117
|
if (list) {
|
|
116
118
|
for (var i = 0; i < list.length; i++) {
|
|
117
119
|
var o = list[i];
|
|
118
|
-
ret = o.func(ret, ...args);
|
|
120
|
+
ret = o.func(ret, model, ...args);
|
|
119
121
|
}
|
|
120
122
|
}
|
|
121
123
|
return ret;
|
package/index.js
CHANGED
|
@@ -141,7 +141,7 @@ Tpl.prototype.loadFunc = function(m) {
|
|
|
141
141
|
return _this.render(body, model, options);
|
|
142
142
|
}
|
|
143
143
|
m.hook_action = function(name, ...args) {
|
|
144
|
-
return $.hook.runAction(name,
|
|
144
|
+
return $.hook.runAction(name, m, ...args);
|
|
145
145
|
}
|
|
146
146
|
m.hook_filter = function(name, content, ...args) {
|
|
147
147
|
if (!content) {
|
package/package.json
CHANGED
package/template/game/bar.html
CHANGED
package/test.js
CHANGED
|
@@ -47,17 +47,17 @@ async function test() {
|
|
|
47
47
|
tpl.current_theme = "game";
|
|
48
48
|
tpl.dir = "";
|
|
49
49
|
|
|
50
|
-
$.hook.addAction('test', function(
|
|
51
|
-
console.log(m);
|
|
50
|
+
$.hook.addAction('test', function(m, param) {
|
|
51
|
+
// console.log(param, m);
|
|
52
52
|
return "<div>你好吗?</div>";
|
|
53
53
|
}, 2, "测试动作2");
|
|
54
54
|
|
|
55
|
-
$.hook.addAction('test', function(
|
|
55
|
+
$.hook.addAction('test', function(m, param) {
|
|
56
56
|
return "<div>你好!</div>";
|
|
57
57
|
}, 1, "测试动作1");
|
|
58
58
|
|
|
59
|
-
$.hook.addFilter('test', function(ret, m) {
|
|
60
|
-
console.log(m);
|
|
59
|
+
$.hook.addFilter('test', function(ret, m, param) {
|
|
60
|
+
// console.log(ret, param, m);
|
|
61
61
|
return ret.replace("你", "您");
|
|
62
62
|
}, 1, "测试过滤");
|
|
63
63
|
|