An asynchronous javascript micro framework for event broadcasts along routes and channels.
Original code came from @jstandish https://github.com/jstandish/nerve
He did a great job, but there are some flaws in his code and I decided to make major refactoring.
Listening to any message on a channel
nerve.on({
channel: 'some-channel',
callback: function( context ) {
// some functionality
},
});
Listening to a specific route on a channel
nerve.on({
channel: 'some-channel',
route: 'some-route',
callback: function( context ) {
// some functionality
}
});
Listening to a channel or route but using a different scope upon event consumption
this.outsideScopeProperty = 'you can see me';
var that = this;
nerve.on({
channel: 'some-channel',
route: 'some-route',
callback: function( context ) {
console.log( this.outsideScopeProperty === 'you can see me' );
},
scope: this
});
In the following example 'context' will be send as parameter to the callback
nerve.send({
channel: 'some-channel',
route: 'some-route',
context: { someData: true }
});
Removing a listener for a channel
nerve.off({
channel: 'some-channel'
});
Removing a listener from a specific channel's route
nerve.off({
channel: 'some-channel',
route: 'some-route'
});
Removing a listener from a specific channel's route that has a different scope
var that = this;
nerve.off({
channel: 'some-channel',
route: 'some-route',
scope: that
});