Nanoseconds Produce Minutes
Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

psst

2.0.0 • Public • Published

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 psst
var 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

Install

npm i psst

DownloadsWeekly Downloads

1

Version

2.0.0

License

MIT

Last publish

Collaborators

  • avatar