unjs / unjs/hookable

Support `.callHookOnce`

Open
#105 0 comments 1 reaction 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

Usually, there are some hooks that are to be called only once.

In the current API, it is delegated to hook consumers to use hookOnce on them; if they don't and use hook insteam, small callbacks might remain in memory.

A new .callHookOnce API can make sure it from provider-side and automatically discard all listeners after.

Second idea: We could also warn if a hook register attempt after callOnce that it won't be called and likely a late register issue

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 reading the repository's existing hook and hookOnce APIs and their tests. Determine the expected provider-side behavior for a new callHookOnce API, including listener disposal and the optional warning for late registrations. Done means the API behavior is covered by tests and its listener lifecycle is unambiguous.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
developer-experience, 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.