Hooks
Usage
import { Hooks } from "@tsed/hooks";
Overview
class Hooks {
has(event: string): boolean;
on(event: string, ref: HookRef, cb: HookListener): this;
on(event: string, cb: HookListener): this;
once(event: string, ref: HookRef, cb: HookListener): this;
once(event: string, cb: HookListener): this;
off(ref: HookRef): this;
off(event: string, cb: HookListener): this;
emit(event: string): void;
emit(event: string, args: unknown[]): void;
emit(event: string, ref: HookRef, args?: unknown[]): void;
asyncEmit(event: string): Promise<void>;
asyncEmit(event: string, args: unknown[]): Promise<void>;
asyncEmit(event: string, ref: HookRef, args?: unknown[]): Promise<void>;
alter<Arg = unknown, AlteredArg = Arg>(event: string, value: Arg, args?: unknown[], callThis?: unknown): AlteredArg;
asyncAlter<Arg = unknown, AlteredArg = Arg>(event: string, value: Arg, args?: unknown[], callThis?: unknown): Promise<AlteredArg>;
destroy(): void;
}
has
has(event: string): boolean;
Check if an event has listeners
on
on(event: string, ref: HookRef, cb: HookListener): this;
event (
string
): The event nameref (
HookRef
): The reference of the listenercb (
HookListener
): The callback
Listen a hook event
on
on(event: string, cb: HookListener): this;
event (
string
): The event namecb (
HookListener
): The callback
Listen a hook event
once
once(event: string, ref: HookRef, cb: HookListener): this;
event (
string
): The event nameref (
HookRef
): The reference of the listenercb (
HookListener
): The callback
Listen a hook event once
once
once(event: string, cb: HookListener): this;
Listen a hook event once
off
off(ref: HookRef): this;
Remove a listener attached to an event
off
off(event: string, cb: HookListener): this;
Remove a listener attached to an event
emit
emit(event: string): void;
- event (
string
): The event name
Trigger an event without arguments.
emit
emit(event: string, args: unknown[]): void;
Trigger an event and call listener.
emit
emit(event: string, ref: HookRef, args?: unknown[]): void;
event (
string
): The event nameref (
HookRef
): The reference of the listenerargs (
unknown[]
): Optional. The arguments
Trigger an event with arguments and call only listener attached to the given ref.
asyncEmit
asyncEmit(event: string): Promise<void>;
- event (
string
): The event name
Trigger an event and call async listener.
asyncEmit
asyncEmit(event: string, args: unknown[]): Promise<void>;
asyncEmit
asyncEmit(event: string, ref: HookRef, args?: unknown[]): Promise<void>;
alter
alter<Arg = unknown, AlteredArg = Arg>(event: string, value: Arg, args?: unknown[], callThis?: unknown): AlteredArg;
Trigger an event, listener alter given value and return it.
asyncAlter
asyncAlter<Arg = unknown, AlteredArg = Arg>(event: string, value: Arg, args?: unknown[], callThis?: unknown): Promise<AlteredArg>;
Trigger an event, async listener alter given value and return it.
destroy
destroy(): void;