Skip to content

Latest commit

 

History

History
99 lines (61 loc) · 2.81 KB

README.md

File metadata and controls

99 lines (61 loc) · 2.81 KB
Български Deutsch English Русский Українська

EventEmitter

Release License clasp

EventEmitter is an object that implements event handling.

Installation

  1. Open your project in Google Apps Script Dashboard.
  2. Copy the contents of the emitter.js file and paste it into a new file in your Google Apps Script project.

Documentation

For detailed documentation, please visit the Wiki page.

Usage

Creating an EventEmitter instance

const emitter = EventEmitter.create();

Subscribing to an event

emitter.on('eventName', function(data) {
  console.log(data);
});

Initiating an event

emitter.emit('eventName', { data: true });

Unsubscribing from an event

function eventHandler(data) {
  console.log(data);
}

emitter.on('eventName', eventHandler);
emitter.off('eventName', eventHandler);

One-time event subscription

emitter.once('eventName', function(data) {
  console.log(data);
});

Custom events

  • 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.

Tasks

  • Need to test the method emitter.prependListener(eventName, listener).
  • Need to test the method emitter.prependOnceListener(eventName, listener).

Contributing

Please read CONTRIBUTING.md for details on how to contribute to this project.

Changelog

For a detailed list of changes and updates, please refer to the CHANGELOG.md file.

License

This project is licensed under the LICENSE.md file.