Listener ID to remove (ID is the return value from Otis.events.on
or Otis.events.once
)
Attaches an event listener to the Otis application.
Usage
Name of the event to listen to; e.g., "message", "expand", "contract", "quote", "appointment", "contact"
Callback function to be executed whenever the given event is emitted; receives the event data as an argument
The value to use as this
when the handler function is executed (optional)
An ID for this listener; you can remove this listener by passing the returned ID to Otis.events.off
Exactly like Otis.events.on
, but only executes the given handler once.
Usage
Name of the event to listen to; e.g., "message", "expand", "contract", "quote", "appointment", "contact"
Callback function to be executed once the given event is emitted; receives the event data as an argument
The value to use as this
when the handler function is executed (optional)
An ID for this listener; you can remove this listener by passing the returned ID to Otis.events.off
Remove an event listener that was previously attached with
Otis.events.on
orOtis.events.once
. Pass a listener ID (returned from theon
/once
methods) to this method to remove that listener and prevent it from executing its handler function in the future.const messagesDuringEachExpansion = {}; let currentExpansionTimestamp; let messageListenerId; Otis.events.on('expand', () => { console.log('Starting collection for this expansion...'); currentExpansionTimestamp = new Date().getTime().toString(); messagesDuringEachExpansion[currentExpansionTimestamp] = []; messageListenerId = Otis.events.on('message', (event) => { messagesDuringEachExpansion[currentExpansionTimestamp].push(event); }); }); Otis.events.on('contract', () => { console.log('Finalizing collection for this expansion...') Otis.events.off(messageListenerId); }); // After a few iterations of expansion/contraction and messages sent during // each, the `messagesSentDuringEachExpansion` object should look like this: // { // "1589562996085": [MessageEventData, MessageEventData, MessageEventData], // "1589565019455": [MessageEventData], // "1589569346612": [MessageEventData, MessageEventData], // }