CommandKitEventsChannel
CommandKitEventsChannel
Represents a channel for emitting and listening to events in CommandKit. This class provides methods to manage event listeners and emit events within a specific namespace.
class CommandKitEventsChannel {
constructor(commandkit: CommandKit)
to(namespace: string) => ;
on(namespace: string, event: string, listener: ListenerFunction) => ;
off(namespace: string, event: string, listener: ListenerFunction) => ;
once(namespace: string, event: string, listener: ListenerFunction) => ;
emit(namespace: string, event: string, args: any[]) => ;
removeAllListeners(namespace: string) => void;
removeAllListeners(namespace: string, event: string) => void;
removeAllListeners(namespace: string, event?: string) => void;
}
constructor
(commandkit: CommandKit) => CommandKitEventsChannel
Creates a new instance of CommandKitEventsChannel.
to
(namespace: string) =>
Creates a namespaced event channel. This allows you to manage events within a specific namespace, preventing conflicts with other event channels. This is useful for organizing events related to different parts of your application.
Example
commandkit.events.to('customNamespace').emit('eventName', data);
on
(namespace: string, event: string, listener: ListenerFunction) =>
Register an event listener for a specific event within the namespace.
off
(namespace: string, event: string, listener: ListenerFunction) =>
Unregister an event listener for a specific event within the namespace.
once
(namespace: string, event: string, listener: ListenerFunction) =>
Register an event listener that will be called only once for a specific event within the namespace.
emit
(namespace: string, event: string, args: any[]) =>
Emit an event within the specified namespace, calling all registered listeners.
removeAllListeners
(namespace: string) => void
Remove all listeners for a specific event or all events within the namespace.
removeAllListeners
(namespace: string, event: string) => void
removeAllListeners
(namespace: string, event?: string) => void