Class HooksEmitter<THooks>

A class for registering, un-registering, and calling hooks. The events that can be hooked into are defined in the Hooks type, but any string can be used as an event name, allowing plugins to define their own hooks.

Each registered hook is awaited in series to ensure that hooks are called in the order they were registered.

Type Parameters

Constructors

Methods

Constructors

Methods

  • Call all hooks for a given event.

    Type Parameters

    • TEventName extends string | number | symbol

    Parameters

    • event: TEventName

      The event to call the hooks for.

    • Rest...args: THooks[TEventName] extends ((...args: any) => any)
          ? Parameters<any[any]>
          : any[]

      The arguments to pass to the hooks.

    Returns Promise<void>

  • Type Parameters

    • TEventName extends string | number | symbol = keyof THooks

    Parameters

    Returns Promise<void>

  • Un-register a hook for a given lifecycle event.

    Type Parameters

    • TEventName extends string | number | symbol

    Parameters

    Returns boolean

    Whether a hook was un-registered.

  • Type Parameters

    • TEventName extends string | number | symbol

    Parameters

    Returns boolean

  • Register a new hook for a given lifecycle event.

    Type Parameters

    • TEvent extends string | number | symbol

    Parameters

    • event: TEvent

      The event to register the hook for.

    • hook: THooks[TEvent]

      The function to call when the event is triggered.

    Returns void

  • Type Parameters

    • TEvent extends string | number | symbol

    Parameters

    Returns void

  • Register a new hook for a given lifecycle event that will only be called once, then un-registered.

    Type Parameters

    • TEventName extends string | number | symbol

    Parameters

    Returns void

  • Type Parameters

    • TEventName extends string | number | symbol

    Parameters

    Returns void