@vaalentin/event-dispatcher

1.0.3 • Public • Published

Event Dispatcher

Build Status

Simple event dispatcher.

Installation

$ npm install --save @vaalentin/event-dispatcher

Usage

import EventDispatcher from '@vaalentin/event-dispatcher';

class App extends EventDispatcher {
  start() {
    this.dispatchEvent('start', performance.now());
  }
}

const app = new App();

app.addEventListener('start', time => {
  console.log(`app started at: ${time}`);
});

app.start();

API

dispatcher = new EventDispatcher()

Can be used directly, or extended.

dispatcher.addEventListener(type, cb)

Add listener cb to type. dispatcher.on(type, cb) is an alias.

dispatcher.removeEventListener(type, cb)

Remove listener cb from 'type'. dispatcher.off(type, cb) is an alias.

dispatcher.dispatchEvent(type, ...data)

Call all listeners of type and pass data. dispatcher.trigger(type, ...data) is an alias.

dispatcher.dispose()

Delete instance.

License

MIT, see LICENSE.md for more details.

Readme

Keywords

none

Package Sidebar

Install

npm i @vaalentin/event-dispatcher

Weekly Downloads

0

Version

1.0.3

License

MIT

Last publish

Collaborators

  • vaalentin