Javascript 7.x

prependOnceListener

Adds a one-time listener function for an event to the beginning of the listeners array.
The next time that event is triggered, this listener is removed, and then invoked.

Arguments

Copied to clipboard!
prependOnceListener(eventName, callback);

Argument Type Description
eventName
string
The name of the event
callback
function
Function to call when the event is triggered

Return

The KuzzleEventEmitter instance.

Usage

Copied to clipboard!
const eventEmitter = new KuzzleEventEmitter();
eventEmitter.addListener('myEvent', () => console.log('listener1'));
eventEmitter.prependOnceListener('myEvent', () => console.log('listener2'));
// Prints:
//   listener2
//   listener1
eventEmitter.emit('myEvent');
// Prints: listener1
// (the listener function printing "listener2" as since been removed)
eventEmitter.emit('myEvent');