包装方法 流星方法
wrapMethod Meteor methods
我正在研究这个演示文稿,构建大型流星应用程序,我喜欢wrapMethod()的想法,但似乎我不能像在示例中那样使用它。
这是我的代码。
Meteor.methods({
'EX.Accounts.Methods.updateProfileData' : function(userId, firstName, secondName) {
check([firstName, secondName], [String]);
Meteor.users.update(userId, {
$set: {
'profile.firstName': firstName,
'profile.lastName': secondName,
'profile.isRegisted': true
}
});
}
});
EX.Accounts.Methods.updateUserProfile = EX.wrapMethod('EX.Accounts.Methods.updateProfileData');
但是我得到了这个错误。
类型错误:对象 # 没有方法"wrapMethod"
我错过了一些我知道的东西,但找不到有关此"wrapMethod"
的任何信息
更新
也试试
_.extend(EX.Accounts.Methods,{
updateUserProfile : EX.Accounts.Methods.updateProfileData
});
这不会返回错误,但我在全局命名空间上看不到该方法。
前任。Accounts.Methods 很清楚,没有方法。
我认为开发人员在他的PB obejct上创建了wrapMethod
的方法。正如你在这里看到的,流星中没有所谓的wrapMethod
。我猜他们写了这样的东西:
PB.wrapMethod = function wrapMethod (meteorMethod) {
return function wrappedMeteorMethod (/*arugments*/) {
Meteor.apply(meteorMethod, arguments)
}
}
我觉得挺整齐的。顺便说一句:正如你所看到的,我喜欢命名我的匿名函数。使调试更好。
在 ES6 中,这变成了一种美:
wrapMethod(method) {
return (...args) => Meteor.call(method, ...args);
}
相关文章:
- 我需要把createUser代码放在流星方法中吗
- MeteorJS使用流星调用和流星方法时的无限循环
- 插入失败:流星 1.3 中的方法并做出反应
- 如何在流星js中为对象添加方法
- 返回流星呼叫方法
- 页面加载时的流星方法
- Router.go 方法使路由页面流星变灰的问题
- 在帮助程序函数中使用 for 循环的正确方法 |流星
- 流星,如何将回调和错误传递给调用方方法
- 渲染流星模板时执行的茉莉花测试方法
- 在茉莉花中传递“this”对象流星方法
- 为流星方法设置 cron 作业
- 要打包的命名空间流星方法
- 找不到流星调用方法
- 流星动态创建对象并引用它们?有没有一种简单的方法可以做到这一点
- 在流星中检索用户输入的最快方法
- 流星 - 从发布请求中获取文件的最佳方法是什么
- 铁路由器:通过流星方法将数据传递给客户端
- 重置方法对流星对象无效
- 包装方法 流星方法