unjs / unjs/hookable

Allow hooking into listeners

Open
#117 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
TypeScript
Stars
960
Forks
43
Avg merge
19m
Merged PRs (30d)
1

Description

Describe the feature

Currently it is possible to only hook into the callHook using beforeEach and afterEach but it would be also useful to be able to hook into hook listener e.g. onListener.

This would allow creating a better logger:

10:08:06 hook called app:user:registered (emit)
10:08:06 hook listener app:user:registered (listen)
10:08:06 hook listener app:user:registered (listen)
10:08:06 hook listener app:user:registered (listen)

Currently it is not possible to know when a listener has handled a hook.

Additional information
  • Would you be willing to help implement this feature?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the callHook implementation and the beforeEach, afterEach, and listener dispatch entry points in the TypeScript source. Trace how listeners are invoked and determine where an onListener callback could observe each handled hook. Define the callback behavior and add coverage for emitted hooks with multiple listeners, including the logger scenario described in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.