Skip to content

alexeyoganezov/wrecked-radio

Repository files navigation

WreckedRadio

CircleCI Coverage Status

WreckedRadio is a message bus implementation that supports both publish-subscribe and request-reply patterns.

  • 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

// Add event handler
channel.on('user-login-success', user => console.log(`Oh, hi ${user.name}`));

// Trigger an event
channel.trigger('user-login-success', { name: 'Mark' });

// Add and remove event handler
const unsubscribe = channel.on('user-login-success', () => null);
unsubscribe();

Request passing

// Add request handler
channel.reply('get-greeting', user => `Oh, hi ${user.name}`);

// Make a request
const greeting = channel.request('get-greeting', { name: 'Mark' });

// Remove request handler
channel.stopReplying('get-greeting');

Links

Detailed API Reference

Licensing

MIT License

About

Message bus implementation supporting both publish-subscribe and request-reply patterns

Resources

License

Stars

Watchers

Forks

Packages

No packages published