Support chainable hooks
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 960
- Forks
- 43
- Avg merge
- 19m
- Merged PRs (30d)
- 1
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 https://github.com/unjs/community/discussions/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
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the existing hook-calling API around the proposed callHookWith and callHookChained forms, then compare them with the chainableCaller example in the issue. Resolve whether chaining is configured when hooks are registered or selected at call time, and define tests that verify sequential execution, argument flow, and the final result.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- developer-experience
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100