Reputation: 1489
I was looking into this presentation, building large meteor applications, and I like the idea of the wrapMethod(), but it seems like I can't use it like on the example.
Here is my code.
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');
But I got this error.
TypeError: Object # has no method 'wrapMethod'
I'm missing something I know but just can't find any information about this "wrapMethod"
Update
Also try with
_.extend(EX.Accounts.Methods,{
updateUserProfile : EX.Accounts.Methods.updateProfileData
});
Which doesn't return an error but I don't see the method on the global namespace.
EX.Accounts.Methods is clear with no methods.
Upvotes: 0
Views: 68
Reputation: 11
In ES6 this becomes a beauty:
wrapMethod(method) {
return (...args) => Meteor.call(method, ...args);
}
Upvotes: 1
Reputation: 2386
I think the developer created the method wrapMethod
on his PB obejct. As you can see here there is nothing called wrapMethod
in Meteor. I guess they wrote something like this:
PB.wrapMethod = function wrapMethod (meteorMethod) {
return function wrappedMeteorMethod (/*arugments*/) {
Meteor.apply(meteorMethod, arguments)
}
}
I think it's kinda neat. Btw.: As you can see i like to name my anonymous functions. Makes debugging nicer.
Upvotes: 1