2.0.0 • Published 10 years ago
psst v2.0.0
psst.js
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.
Installing
$ npm install psstvar psst = require('psst');or
<script src="https://rawgit.com/flesch/psst.js/master/index.js"></script>Using
psst.js supports both a single global listener (psst.on), or many independent listeners (new psst()).
var listener = new psst();Subscribe/On
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.
Subscribe Once
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.
Unsubscribe/Off
listener.off(subscription);psst.off(subscription);Publish/Emit
listener.emit('topic', 'Hello World!');psst.emit('topic', 'Hello World!');License
Released under the MIT License: http://flesch.mit-license.org