npm.io
0.0.1 • Published 9 years ago

awesome-channels

Licence
ISC
Version
0.0.1
Deps
1
Vulns
1
Weekly
0

Installation

npm install awesome-channels

import/require the library

import { Channel } from 'awesome-channels';

Usage

Channels work within a namespace. All publishers/consumers that wish to communicate should be using the same namespace.

The recommended namespacing is 'project-namesub-page-name' ommitting the sub-page-name if not appropriate. For example 'web-applicationsign-up'.

var channel = new Channel('web-application:users:sign-up');

To notify consumers that an event occurred we use the 'emit' method on the instance of the channel

channel.emit('done', {studentId: 1});

to be alerted that an event occurred we use subscribe to the event using the 'on' method

channel.on('done', function (payload) {
   console.log(payload);
   // in this example the console would print '{studentId: 1}'
});