Skip to content

An asynchronous javascript micro framework for event broadcasts along routes and channels.

Notifications You must be signed in to change notification settings

artemdemo/nerve

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nerve

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 channels and routes - nerve.on()

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
});

Sending events to channels and routes - nerve.send()

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 listeners from a channel or route - nerve.off()

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
});

About

An asynchronous javascript micro framework for event broadcasts along routes and channels.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published