An event publisher implementation that communicates based on type property.
npm install typed-event-publisher
import EventPublisher from 'typed-event-publisher'
const eventPublisher = new EventPublisher();
// Subscribe all events
eventPublisher.subscribe((event) => {
console.log(event); //=> { bar: 'baz', type: 'foo' }
});
// Subscribe foo events
eventPublisher.on('foo', (event) => {
console.log(event); //=> { bar: 'baz', type: 'foo' }
});
eventPublisher.publish('foo', { bar: 'baz' });
Import in your favorite style.
// Pattern 1: Using a default export
import EventPublisher from 'typed-event-publisher'
// Pattern 2: Using named exports
import { EventPublisher, Subscription } from 'typed-event-publisher'
// Pattern 3: Using both a default export and named exports
import EventPublisher, { Subscription } from 'typed-event-publisher'
# Set up
npm install
# Compile JavaScript files
npm run compile
# Watch changes of JavaScript files
npm run watch
# Run tests
npm run test