UNPKG

@obsidize/logger

Version:
26 lines (25 loc) 897 B
/** * Callback that accepts a single value which was * emitted from the `EventEmitter` instance. */ export type EventEmitterDelegate<T> = (value: T) => any; /** * Lightweight event broadcaster. * * While this class' primary use in the library is for * sending log events to registered listeners, it * is defined to be generic, and can technically * emit any type of value. * * Feel free to use this for non-logging things since * javascript has no built-in observer pattern... */ export declare class EventEmitter<T> { private mListeners; get listenerCount(): number; emit<R extends T = T>(value: R): this; hasListener<R extends T = T>(listener: EventEmitterDelegate<R>): boolean; addListener<R extends T = T>(listener: EventEmitterDelegate<R>): this; removeListener<R extends T = T>(listener: EventEmitterDelegate<R>): this; removeAllListeners(): this; }