SDK
SDK Javascript v6.x
1

You are currently looking at the documentation of a previous version of Kuzzle. We strongly recommend that you use the latest version. You can also use the version selector in the top menu.

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');