philip21.js

@philip21/eventbus

Installation

npm install @philip21/eventbus --save

Getting Started

import EventBus from '@philip21/eventbus';

const eventBus = new EventBus();

eventBus.on('a', console.log);
eventBus.on({
  b: console.log,
  c: console.log,
});

eventBus.emit('a', 2);
eventBus.emit('b', 'p');
eventBus.emit('c', { n: 1 });

Type Inference Support

interface EventDefinition {
  a: 1 | 2 | 3;
  b: 'p';
}

const eventBus = new EventBus<EventDefinition>().on({
  a: console.log,
  b: console.log,
});

/**
 * or
 *
 * new EventBus<{
 *   a: 1 | 2 | 3;
 *   b: 'p';
 * }>();
 */

Specifications