EventEmitter is an object that implements event handling.
- Open your project in Google Apps Script Dashboard.
- Copy the contents of the emitter.js file and paste it into a new file in your Google Apps Script project.
For detailed documentation, please visit the Wiki page.
const emitter = EventEmitter.create();
emitter.on('eventName', function(data) {
console.log(data);
});
emitter.emit('eventName', { data: true });
function eventHandler(data) {
console.log(data);
}
emitter.on('eventName', eventHandler);
emitter.off('eventName', eventHandler);
emitter.once('eventName', function(data) {
console.log(data);
});
newListener
: Triggered every time new listeners are added. Passes the event name and a reference to the added listener.removeListener
: Triggered every time existing listeners are removed. Passes the event name and a reference to the removed listener.error
: Triggered when an error occurs. If the event has no subscribers, an exception is thrown.
- Need to test the method
emitter.prependListener(eventName, listener)
. - Need to test the method
emitter.prependOnceListener(eventName, listener)
.
Please read CONTRIBUTING.md for details on how to contribute to this project.
For a detailed list of changes and updates, please refer to the CHANGELOG.md file.
This project is licensed under the LICENSE.md file.