evitter
TypeScript icon, indicating that this package has built-in type declarations

4.0.0 • Public • Published

evitter

npm npm npm

EventEmitter with parametrized subscriptions

Features

  • ✂️ Zero dependencies
  • 🚀 Lightweight and fast
  • 📦 Easy to use out of the box
  • 💯 100% test coverage

Getting started

  • Install with npm:
npm install --save evitter
  • Import as ES module:
import {EventEmitter} from 'evitter';

or as CommonJS module:

const {EventEmitter} = require('evitter');

API

import {EventEmitter} from 'evitter';

const emitter = new EventEmitter();
const callback = () => {};
let unsubscribe = emitter.on('event1', callback); // simple subscription

unsubscribe(); // remove subscription
emitter.on('event2', {param1: 1}, callback); // subscription with parameters

emitter.emit('event1', 2); // call all 'event1' events
emitter.emit('event2', {param1: 1}, {}); // call all 'event2' events that match parameters
emitter.emit('event2', {param1: 1, params2: 4}, []); // no subscriptions there

emitter.getCallbacks('event1'); // [callback]
emitter.getCallbacks('event2', {param1: 1}); // [callback]
emitter.getCallbacks('event2', {param1: 2}); // []
emitter.getCallbacks('event2', {param2: 'some'}); // []

emitter.off(); // unsubscribe from all events

Package Sidebar

Install

npm i evitter

Weekly Downloads

2

Version

4.0.0

License

MIT

Unpacked Size

10.6 kB

Total Files

8

Last publish

Collaborators

  • webschik