@boost/event
Version:
An event system with multiple emitter patterns.
43 lines • 1.5 kB
TypeScript
import type { Listener, Unlistener, WildstarScope } from './types';
export declare abstract class BaseEvent<Return, Args extends unknown[], Scope extends string = string> {
listeners: Map<"*" | Scope, Set<Listener<Args, Return>>>;
name: string;
constructor(name: string);
/**
* Remove all listeners from the event.
*/
clearListeners(scope?: Scope): this;
/**
* Return a set of listeners for a specific event scope.
*/
getListeners(scope?: Scope): Set<Listener<Args, Return>>;
/**
* Return a list of all scopes with listeners.
*/
getScopes(): (Scope | WildstarScope)[];
/**
* Register a listener to the event.
*/
listen(listener: Listener<Args, Return>, scope?: Scope): Unlistener;
/**
* Register a listener to the event that only triggers once.
*/
once(listener: Listener<Args, Return>, scope?: Scope): Unlistener;
/**
* Remove a listener from the event.
*/
unlisten(listener: Listener<Args, Return>, scope?: Scope): this;
/**
* Validate the listener is a function.
*/
protected validateListener<L>(listener: L): L;
/**
* Validate the name/scope match a defined pattern.
*/
protected validateName<N extends string>(name: N, type: string): N;
/**
* Emit the event by executing all scoped listeners with the defined arguments.
*/
abstract emit(args: unknown, scope?: Scope): unknown;
}
//# sourceMappingURL=BaseEvent.d.ts.map