1.2.0 • Published 14 days ago

@tmbr/emitter v1.2.0

Weekly downloads
-
License
-
Repository
github
Last release
14 days ago

Emitter

A simple event emitter class, similar to tiny-emitter and mitt.

npm install @tmbr/emitter
import Emitter from '@tmbr/emitter';

const emitter = new Emitter();

function callback(e) {
  alert(`Hello, ${e.name}!`);
}

// subscribe to an event
emitter.on('example', callback);

// dispatch an event with data
emitter.emit('example', {name: 'World'});

// unsubscribe from an event
emitter.off('example', callback);

// unsubscribe from an event with the returned cleanup function
const off = emitter.on('example', e => alert(`Hello, ${e.name}!`));
off();

// destroy and remove all subscriptions
emitter.destroy();
1.2.0

14 days ago

1.1.0

5 months ago

1.0.0

7 months ago