-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(hooks): Refactor .params, .props and .defaults into hooks #37
Conversation
I think this PR is a regression: As I say here #36 (comment) the hook manager assures us that what manages the parameters is always executed before the rest of the hooks, I cannot know |
Yeah, you're totally right and I ran into this problem literally right away 🤦 I like having it as a hook though since it's more consistent, less code to maintain and it can be faster. Should we bring back the options again then? const { hooks, middleware } = require('@feathersjs/hooks');
const sayHello = async name => {
return `Hello ${name}!`;
};
const wrappedSayHello = hooks(sayHello, middleware([
async (context, next) => {
console.log(context.name);
await next();
}
], {
params: ['name'],
defaults: context => ({ name: 'Dave', params: {} }),
properties: { method: 'Something' }
})); This would register a standard hook that always runs first and initializes those properties. |
I'm fine with the options, it's probably the best solution |
This pull request is another refactoring that turns
params
,props
anddefaults
intosetContext.params
,setContext.properties
andsetContext.defaults
hooks. Performance appears to be about the same (or better when you do not use those hooks) with a more simplified API and smaller code base (client side bundle size reduced by ~20%). It can be used like this:Closes #36
Closes #38