es6-eventhub

1.0.3 • Public • Published

ES6 Events

Licence Tests

A simple event emitter and listener built in ES6.

Methods

eventhub.on

Init listener on string.

eventhub.on('string', handler);

eventhub.onAll

Init listener on all strings.

eventhub.on('string', handler);

eventhub.once

Fire event only once, then remove the event.

eventhub.once('string', handler);

eventhub.emit

Fire event on string with arguments.

eventhub.emit('string', ...args);

Fire event on string without arguments.

eventhub.emit('string');

eventhub.remove

Remove event from the eventhub list with the same string and handler.

eventhub.remove('event', handler);

Remove event from the eventhub list with the same string.

eventhub.remove('string');

Usage

import Eventhub from 'eventhub';
const eventhub = new Eventhub();
 
eventhub.on('text-change', text => {
  console.log('Text changed to', text);
});
 
eventhub.emit('text-change', 'New Text');

or

import Eventhub from 'eventhub';
const eventhub = new Eventhub()
  .on('text-change', text => {
    console.log('Text changed to', text);
  })
  .emit('text-change', 'New Text');

License

MIT

Package Sidebar

Install

npm i es6-eventhub

Weekly Downloads

1

Version

1.0.3

License

MIT

Unpacked Size

18.6 kB

Total Files

8

Last publish

Collaborators

  • chrisru