3.1.0 • Published 8 years ago
channel-dispatcher v3.1.0
channel-dispatcher
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
8 years ago
3.0.0
8 years ago
2.0.3
8 years ago
2.0.2
8 years ago
2.0.1
8 years ago
2.0.0
8 years ago
1.1.5
8 years ago
1.1.4
8 years ago
1.1.3
8 years ago
1.1.2
8 years ago
1.1.1
8 years ago
1.1.0
8 years ago
1.0.3
8 years ago
1.0.2
8 years ago
1.0.1
8 years ago
1.0.0
8 years ago
0.0.4
8 years ago
0.0.3
8 years ago
0.0.2
8 years ago
0.0.1
8 years ago