This is yet another small Pub/Sub library, however unlike many other implementations, the subscribe method returns an object that describes the channel and callback.
$ npm install psst
var psst = require('psst');
or
<script src="https://rawgit.com/flesch/psst.js/master/index.js"></script>
psst.js supports both a single global listener (psst.on
), or many independent listeners (new psst()
).
var listener = new psst();
var subscription = listener.on('topic', function(msg){
console.log(msg);
});
var subscription = psst.on('topic', function(msg){
console.log(msg);
});
subscription
is a unique object that contains the channel and callback.
var subscription = listener.once('topic', function(msg){
console.log(msg);
});
var subscription = psst.once('topic', function(msg){
console.log(msg);
});
This subscription
is removed from the subscriber's list after the callback has been executed.
listener.off(subscription);
psst.off(subscription);
listener.emit('topic', 'Hello World!');
psst.emit('topic', 'Hello World!');
Released under the MIT License: http://flesch.mit-license.org