-
Notifications
You must be signed in to change notification settings - Fork 29
normalize parameters #1
Comments
I like UserService.prototype.after = {
create : function (obj, callback) {
console.log(obj);
// => { data : { ... }, id : ..., requestData : { ... }, params : { ... } }
callback(null, obj, callback);
}
}; I noticed it too, that it is a little annoying having to pass all the arguments through all the time, even if you are not using them. This would also allow to make it Express like middleware where you can modify the object and then just call |
So it'd either be: UserService.prototype.after = {
create : function (obj, callback) {
// do stuff
callback(null, obj);
}
}; Or possibly more Express like: UserService.prototype.after = {
create : function (obj, next) {
// modify obj directly
next();
}
}; I'd prefer the latter, as it'd make it harder to forget or break something. |
I think we can do both. If the callback isn't passed any parameters use the original data object otherwise the one returned by the callback. Like the idea, I think I might get to implementing it today or tomorrow. |
I implemented the new API via e140451 (probably should've made it a pull request but oh well). Looking like this now: Documentation is updated, too and looks like this: todoService.before({
find: function (hook, next) {
if (!hook.params.user) {
return next(new Error('You are not logged in'));
}
next();
},
create: function(hook, next) {
hook.data.createdAt = new Date();
next();
// Or
next(null, hook);
}
}); Will add some examples and make a 0.2.0 if that looks good. |
Closed via e140451 |
I've been playing around with feathers-hooks and I've been trying to find a way to reuse code. As it's easier to understand with an example, consider the following code:
What I would like to do would be something like this:
The only way to achieve this is for the
deletePassword
function to check the number of arguments and act accordingly, which makes the intent less clear in my eyes. Would it be feasible to normalize the parameters to something like the following?The text was updated successfully, but these errors were encountered: