You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While working on #35 I realized that most of what the hook manager does for .params, .props and .defaults could really be done by hooks themselves like this:
import{hooks,middleware,params,props,defaults}from'@feathersjs/hooks';constsayHello=async(firstName,lastName)=>{return`Hello ${firstName}${lastName}!`;};consthelloWithHooks=hooks(sayHello,[params('firstName','lastName'),props({someProperty: true}),defaults((context)=>({lastName: 'unknown'})),async(context,next)=>{// Do things hereawaitnext();}]);
I did a quick benchmark and it seems to be just as fast as the current setup. I find it more consistent than having a separate API.
The text was updated successfully, but these errors were encountered:
Very good points! I will give it a try and see if it also works properly with classes and inheritance. For the first one, if I understand it right, I think you should be able to alias the import to the name you need:
import{hooks,middleware,paramsashookParams}from'@feathersjs/hooks';constsayHello=async(firstName,lastName)=>{return`Hello ${firstName}${lastName}!`;};consthelloWithHooks=hooks(sayHello,[hookParams('firstName','lastName'),async(context,next)=>{// Do things hereawaitnext();}]);
Or just give it better names but I'm not sure what those would be.
While working on #35 I realized that most of what the hook manager does for
.params
,.props
and.defaults
could really be done by hooks themselves like this:I did a quick benchmark and it seems to be just as fast as the current setup. I find it more consistent than having a separate API.
The text was updated successfully, but these errors were encountered: