{{ message }}
feat: add clearHook(name)#135
Merged
Merged
Conversation
pi0
approved these changes
Mar 14, 2026
There was a problem hiding this comment.
🧹 Nitpick comments (1)
test/hookable.test.ts (1)
315-318: Add a parity test forHookableCore.clearHookas well.
Line 315validates non-existent hook safety onHookable, but the same new API was also added toHookableCore. A small parity test would prevent regressions in that path.Proposed test addition
describe("HookableCore", () => { test("basic functionality", async () => { @@ expect(obj.called).toBe(true); }); + + test("clearHook removes only the target hook handlers", async () => { + const hookable = new HookableCore<{ a(): void; b(): void }>(); + const a = vi.fn(); + const b = vi.fn(); + + hookable.hook("a", a); + hookable.hook("a", a); + hookable.hook("b", b); + + hookable.clearHook("a"); + + await hookable.callHook("a"); + await hookable.callHook("b"); + + expect(a).toBeCalledTimes(0); + expect(b).toBeCalledTimes(1); + }); });🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@test/hookable.test.ts` around lines 315 - 318, Add a parity test for HookableCore.clearHook mirroring the existing Hookable test: instantiate HookableCore, call clearHook("test:nonexistent") and assert it does not throw. Target the HookableCore class and its clearHook method (HookableCore.clearHook) so the new test ensures the same non-existent-hook safety behavior as the Hookable test.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@test/hookable.test.ts`:
- Around line 315-318: Add a parity test for HookableCore.clearHook mirroring
the existing Hookable test: instantiate HookableCore, call
clearHook("test:nonexistent") and assert it does not throw. Target the
HookableCore class and its clearHook method (HookableCore.clearHook) so the new
test ensures the same non-existent-hook safety behavior as the Hookable test.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: feab32fd-2ada-4ac1-b2e8-bf51416f4ffb
📒 Files selected for processing (2)
src/hookable.tstest/hookable.test.ts
Member
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

the aim is to allow handlers to be unregistered without requiring the original function references
(I was investigating ways of reducing memory usage in nuxt and thought that unregistering hooks might be useful - and in fact it did save some memory where those hooks closed over other variables, etc. - so thought it might be worth raising here...)
would also be happy to update
removeHookto make the second argument optional if you prefer... and of course, feel free to close if this isn't useful
Summary by CodeRabbit
New Features
Tests