Skip to main content
Version: Next

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.

Signature
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

method
(commandkit: CommandKit) => CommandKitEventsChannel

Creates a new instance of CommandKitEventsChannel.

to

method
(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

method
(namespace: string, event: string, listener: ListenerFunction) =>

Register an event listener for a specific event within the namespace.

off

method
(namespace: string, event: string, listener: ListenerFunction) =>

Unregister an event listener for a specific event within the namespace.

once

method
(namespace: string, event: string, listener: ListenerFunction) =>

Register an event listener that will be called only once for a specific event within the namespace.

emit

method
(namespace: string, event: string, args: any[]) =>

Emit an event within the specified namespace, calling all registered listeners.

removeAllListeners

method
(namespace: string) => void

Remove all listeners for a specific event or all events within the namespace.

removeAllListeners

method
(namespace: string, event: string) => void

removeAllListeners

method
(namespace: string, event?: string) => void