A registry for managing and executing hook handlers. Handlers are executed sequentially in registration order.
const hooks = new HookRegistry<{ beforeRun: (payload: { command: string }) => void;}>();hooks.on('beforeRun', ({ command }) => { console.log('Running command:', command);});hooks.call('beforeRun', { command: 'foo bar' }); // -> 'Running command: foo bar' Copy
const hooks = new HookRegistry<{ beforeRun: (payload: { command: string }) => void;}>();hooks.on('beforeRun', ({ command }) => { console.log('Running command:', command);});hooks.call('beforeRun', { command: 'foo bar' }); // -> 'Running command: foo bar'
An object that maps hook names to their corresponding handler function types. The handler function type should accept a single payload argument.
Call all handlers registered for a hook. Handlers are called sequentially in registration order.
The hook to call.
The args to pass to each handler.
Remove a previously registered handler.
The hook to remove the handler from.
The handler function to remove.
A boolean indicating whether the handler was found and removed.
Register a handler for a hook.
The hook to handle.
The function to execute when the hook is called.
Register a one-time handler that removes itself on execution.
The hook to handle once.
The function to execute once when the hook is called.
A registry for managing and executing hook handlers. Handlers are executed sequentially in registration order.
Example