Skip to content
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

Make hooks more generic #23

Open
claustres opened this issue Jul 10, 2018 · 2 comments
Open

Make hooks more generic #23

claustres opened this issue Jul 10, 2018 · 2 comments

Comments

@claustres
Copy link
Member

claustres commented Jul 10, 2018

A lot of hooks are to be used as before OR after hooks while they could be used in both cases. This is mostly due to the fact that we directly access data or result on the hook object instead of using the generic Feathers utility functions getItems()/replaceItems().

We recently introduced callOnHookItems() to apply a given function on hook items to support such use cases. It should be used whenever possible.

Moreover hooks reading/writing data like readJson/writeJson are writing/reading data to/from a default path like result.data, which is not aware of the type of the hook. The data path should adapt itself to be more easy to use, eg data.data in a before hook and result.data in an after hook.

@claustres
Copy link
Member Author

Another aspect to consider is to be able to use hooks on tasks or jobs. In the last case the main difference occurs when using it as an after hook on a job because result is then resolved as the array of completed tasks. As a consequence if you'd like to access the job options you have to use hook.data and not hook.result, but this might then restrict hook applicability on tasks. Maybe the solution is to use this approach:

let item = getItems(hook)
let option = _.get(item, xxx, _.get(hook.data, xxx))

@claustres
Copy link
Member Author

claustres commented Mar 20, 2019

Since hook.data is always available in before/after hooks for tasks/jobs because we only rely on create operations and transfer data object to result object it seems to be the more generic. Only after job hooks that need to process tasks should rely on specific code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Stand-by
Development

No branches or pull requests

1 participant