wrecked-radio
v1.0.0
Published
Message bus implementation that supports both publish-subscribe and request-reply patterns
Downloads
3
Readme
WreckedRadio
WreckedRadio is a message bus implementation that supports both publish-subscribe and request-reply patterns. It's:
- Written in modern TypeScript
- Fully covered with tests
- As tiny as possible
- Dependency free
Heavily inspired by backbone.radio.
Getting started
Installation
yarn add wrecked-radio
or
npm install --save wrecked-radio
Import and instantiation
import WreckedRadio from 'wrecked-radio';
const radio = new WreckedRadio();
const firstChannel = radio.channel('first-channel');
const secondChannel = radio.channel('second-channel');
Event passing
// Somewhere in event subscriber:
channel.on('user-login-success', user => console.log(`Oh, hi ${user.name}`);
// Somewhere in event publisher:
channel.trigger('user-login-success', { name: 'Mark' });
Request passing
// Somewhere in command processor:
channel.reply('get-greeting', user => `Oh, hi ${user.name}`);
// Somewhere else:
const greeting = channel.request('get-greeting', { name: 'Mark' });