3.1.0 • Published 9 years ago

channel-dispatcher v3.1.0

Weekly downloads
3
License
MIT
Repository
github
Last release
9 years ago

channel-dispatcher

Build Status Coverage Status

A tiny channel subscribe/publish library.

Basic usage.

// require library
var dispatcher = require('channel-dispatcher');

// subscribe callback
// sub is needed to unsubscribe later
var sub = dispatcher.subscribe('test', function(data) {
  console.log(data);
});

// pass data to channel
// in this case 'Hello to channel' will be printed
dispatcher.publish('test', 'Hello to channel');

// unsubscribe callback from channel
sub.unsubscribe();

Using standalone channel object.

// require library
var dispatcher = require('channel-dispatcher');

// get channel object
var channel = dispatcher.getChannel('test');

// subscribe callback
// sub is needed to unsubscribe later
var sub = channel.subscribe(function(data) {
  console.log(data);
});

// pass data to channel
// in this case 'Hello to standalone channel' will be printed
channel.publish('Hello to standalone channel');

// unsubscribe callback from channel
sub.unsubscribe();

Specifying context

You can pass context along with callback

// context object
var context = {foo: "context data"};

// callback
var callback = function(bar) {
  var foo = this.foo;
  console.log(foo + " " + bar);
};

// subscribe callback with context
dispatcher.subscribe('test', callback, context);
// or using channel object
// channel.subscribe(callback, context)

// pass data
// 'context data passed data' will be printed
dispatcher.publish('test', "passed data");

Show warnings

Warnings is disabled by default.

// show warnings
dispatcher.setLogging(true);
3.1.0

9 years ago

3.0.0

9 years ago

2.0.3

9 years ago

2.0.2

9 years ago

2.0.1

9 years ago

2.0.0

9 years ago

1.1.5

10 years ago

1.1.4

10 years ago

1.1.3

10 years ago

1.1.2

10 years ago

1.1.1

10 years ago

1.1.0

10 years ago

1.0.3

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago