interface HookableEvent<T> {
    addPostHook(hook: PostEventHook<T>): EventHookRemove;
    addPreHook(hook: PreEventHook<T>): EventHookRemove;
    trigger<R>(payload: T, action: (() => Promise<R>)): Promise<R>;
}

Type Parameters

  • T

Methods

  • Add a hook to be executed after the event's action when the event is triggered.

    Parameters

    Returns EventHookRemove

    A callback which deletes the added hook.

  • Add a hook to be executed before the event's action when the event is triggered.

    Parameters

    Returns EventHookRemove

    A callback which deletes the added hook.

  • Runs all hooks of a specific event of the given event type.

    Type Parameters

    • R

    Parameters

    • payload: T

      The data which the callback of each hook has access to.

    • action: (() => Promise<R>)

      The action to perform.

    Returns Promise<R>

    A promise of type R.