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
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.
The text was updated successfully, but these errors were encountered:
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))
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.
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
orresult
on the hook object instead of using the generic Feathers utility functionsgetItems()/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 likeresult.data
, which is not aware of the type of the hook. The data path should adapt itself to be more easy to use, egdata.data
in a before hook andresult.data
in an after hook.The text was updated successfully, but these errors were encountered: