wavestation
v1.0.1
Published
A simple pub/sub module
Downloads
86
Readme
Wavestation
A simple pub/sub CommonJS module, based on David Walsh's module @ http://davidwalsh.name/pubsub-javascript
Install
File include
Download the latest wavestation.global.js from http://github.com/InventingWithMonster/wavestation and include it in your HTML document with a script tag, ie:
<script src="/path/to/wavestation.global.js"></script>
This will load Wavestation to the globally-accessible variable wavestation
.
NPM (recommended)
First install Wavestation in your project root.
$ npm install wavestation
Then include in your module using require().
var wavestation = require('wavestation');
Use
Listen
var listener = wavestation.listen('your-channel', function (data) {
console.log(data);
}); // Will log data when 'your-channel' broadcasts
Broadcast
wavestation.broadcast('your-channel', { foo: bar }); // Broadcasts to 'your-channel'
Create broadcaster
var yourChannel = wavestation.newBroadcast('your-channel');
yourChannel({ foo: bar }); // Broadcasts to 'your-channel'
Remove listener
listener.remove();