clide-js
    Preparing search index...

    Class HookRegistry<THooks>

    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'

    Type Parameters

    • THooks extends AnyObject = ClideHooks

      An object that maps hook names to their corresponding handler function types. The handler function type should accept a single payload argument.

    Index

    Constructors

    Methods

    Constructors

    Methods

    • Call all handlers registered for a hook. Handlers are called sequentially in registration order.

      Type Parameters

      • THook extends string | number | symbol | string & {}

      Parameters

      • hook: THook

        The hook to call.

      • ...args: Parameters<HookHandler<THook, THooks>>

        The args to pass to each handler.

      Returns Promise<void>

    • Remove a previously registered handler.

      Type Parameters

      • THook extends string | number | symbol | string & {}

      Parameters

      • hook: THook

        The hook to remove the handler from.

      • handler: HookHandler<THook, THooks>

        The handler function to remove.

      Returns boolean

      A boolean indicating whether the handler was found and removed.

    • Register a handler for a hook.

      Type Parameters

      • THook extends string | number | symbol | string & {}

      Parameters

      • hook: THook

        The hook to handle.

      • handler: HookHandler<THook, THooks>

        The function to execute when the hook is called.

      Returns void

    • Register a one-time handler that removes itself on execution.

      Type Parameters

      • THook extends string | number | symbol | string & {}

      Parameters

      • hook: THook

        The hook to handle once.

      • handler: HookHandler<THook, THooks>

        The function to execute once when the hook is called.

      Returns void