import EventBusHandler from "./eventbus.handler"; export default class EventBus { name: string; /** * The max number of listeners that can * subscribe to a channel */ private maxListeners; /** * Holds the table of all channels for the * current event bus */ private channels; /** * Creates the instance * * @param name The name of the event bus */ constructor(name: string); /** * If the channel exists with a given channel * name, it will be returned. If not, a channel * will be created and returned * * @param channel The name of the channel */ private allocate; /** * Add a listener to a particular channel * @param channel The name of the channel * @param listener The listener to fire on emission * @param context The context for the the listener */ addListener(channel: string | symbol, listener: (...args: any[]) => void, context?: any): this; /** * Add a listener to a particular channel * @param channel The name of the channel * @param listener The listner to fire on emission * @param context The context for the listener */ on(channel: string | symbol, listener: (...args: any[]) => void, context?: any): this; /** * Add a listener to a particular channel that will only fire once * @param channel The name of the channel * @param listener The listener to fire on emission * @param context The context for the listener */ once(channel: string | symbol, listener: (...args: any[]) => void, context?: any): this; /** * Prepend a listener to a particular channel * @param channel The name of the channel * @param listener The listener to fire on emission * @param context The context for the listener */ prependListener(channel: string | symbol, listener: (...args: any[]) => void, context?: any): this; /** * Prepend a listener to a particular channel that only fire once * @param channel The name of the channel * @param listener The listener to fire on emission * @param context */ prependOnceListener(channel: string | symbol, listener: (...args: any[]) => void, context?: any): this; /** * Remove a listener from a channel * * @param channel The name of the channel * @param listener The listener for the channel */ removeListener(channel: string | symbol, listener: (...args: any[]) => void): this; /** * Remove a listener from a channel * * @param channel The name of the channel * @param listener The listener for the channel */ off(channel: string | symbol, listener: (...args: any[]) => void): this; /** * If a channel is supplied, all event listeners for that * channel will be removed. However, if no channel is supplied, * all channels for this event bus will be removed * * @param channel The name of the channle */ removeAllListeners(channel?: string | symbol): this; /** * Set the max number of listeners to be * applied to a particular event channel * * @param n The number of listeners */ setMaxListeners(n: number): this; /** * Get the max number of listeners */ getMaxListeners(): number; /** * Get a list of the listener references for a * particular channel * * @param channel The name of the channel */ listeners(channel: string | symbol): Function[]; /** * Get a list of the event bus handlers for a * particular channel * * @param channel The name of the channel */ handlers(channel: string | symbol): EventBusHandler[]; /** * Broadcast to a listeners for a particular channel * * @param channel The name of the channel * @param args List of arguments to be supplied to the listeners */ emit(channel: string | symbol, ...args: any[]): boolean; /** * Returns a list of all channel names */ channelNames(): Array; /** * Returns the number listeners subscribed to a channel * * @param channel The name of the channel */ listenerCount(channel: string | symbol): number; }