Tiny library for event broadcasting
I started this library as a fork of nice micro framework called Nerve - https://github.com/jstandish/nerve. I decided to create a separate repository because of a fundamental change - drop support for changing scope of the subscription function. Another difference is that vnerv is ES5 compliant and it has Gulp based build system.
Nevertheless basic idea is the same - sending events along channels and routes.
bower install vnerv
or
npm install vnerv
To attach listener use on
function and specify channel with callback:
vnerv.on("channel", function(dto) {
console.log("I am a callback function and I received: " + dto);
});
The callback function will be executed when a message appear on that channel.
Optionally, you can also specify a route:
vnerv.on("channel", 'route', function(dto) {
console.log("I am a callback function and I received: " + dto);
});
To remove listeners use off
function and specify channel from where they should be removed:
vnerv.off("channel");
You can also remove listeners that are only present on given route of the channel
vnerv.off("channel", "route");
Additionally you can remove all default listeners attached to the given channel
vnerv.off("channel", {defaultRoute: true});
To do so, pass configuration object with defaultRoute
flag set to true
as the second argument
You have two basic options:
It will call every callback from all routes on that channel
vnerv.send("channel");
It will call every callback on a specific channel/route combination
vnerv.send("channel", "route");
As a addition in both cases you can attach DTO object which is passed to a callback function, eg.
vnerv.send("channel", "route", {message:'hi'} );
1.0 - Initial version