SDK
SDK Javascript v7.x
2

# removeAllListeners

Removes all listener functions from an event.
If no eventName is specified, removes all listener functions from all events.

# Arguments

Copied to clipboard!
removeAllListeners([eventName]);

Argument Type Description
eventName
string
Optional name of the event

# Return

The KuzzleEventEmitter instance.

# Usage

Copied to clipboard!
const eventEmitter = new KuzzleEventEmitter();
eventEmitter.addListener('myEvent', () => console.log('Caught event "myEvent" (1)'));
eventEmitter.addListener('myEvent', () => console.log('Caught event "myEvent" (2)'));
// Prints:
//   Caught event "myEvent" (1)
//   Caught event "myEvent" (2)
eventEmitter.emit('myEvent');
eventEmitter.removeAllListeners('myEvent');
// Prints nothing: all events have been removed
eventEmitter.emit('myEvent');
if (eventEmitter.listeners('myEvent').length === 0) {
  console.log('Successfully removed all listeners');
}