Open
Description
Describe the feature
Hookable hooks will be called sequentially by default with original arguments. But result of each step is not preserved.
We could export a built-in chainable hook runner.
Example from unjs/community#15 (@ChrisGV04)
const chainableCaller = async (hooks, args) => {
let hookResult: Order = args[0];
for (const hook of hooks) {
hookResult = await hook(hookResult);
}
return hookResult;
}
/** Before create hook */
const orderData = await hooks.callHookWith(chainableCaller, 'orders:before-create', originalOrder);
Some ideas:
- We could export a built-in
chainableCaller
- We could support
hookable.callHookChained(name, <initial>)
that chains first arg - Hooks can be registred as chainable <-- I prefer this most / to define strategy on register instead of use but needs few initial refactors