No description
Find a file
2016-07-11 03:17:17 -07:00
examples added ability to remove all events 2014-03-01 03:28:06 -08:00
.tags fixed bug elrroniously removing last event even if not a match 2016-07-11 03:17:17 -07:00
bower.json fixed bug elrroniously removing last event even if not a match 2016-07-11 03:17:17 -07:00
event-pubsub-browser.js fixed bug elrroniously removing last event even if not a match 2016-07-11 03:17:17 -07:00
event-pubsub.js fixed bug elrroniously removing last event even if not a match 2016-07-11 03:17:17 -07:00
LICENSE Initial commit 2014-02-18 13:48:27 -08:00
package.json fixed removing specific handler from all events case 2014-03-01 03:46:24 -08:00
README.md added NPM stats 2015-08-26 15:15:22 -07:00

Event PubSub

Pubsub events for Node and the browser allowing event scoping and multiple scopes. Easy for any developer level. No frills, just high speed pubsub events!

Pretty GitHub.io site

alt event-pubsub npm details

See NPM stats for event-pubsub

EXAMPLE FILES

  1. Node Pubsub Event Examples
  2. Browser Pubsub Event Examples

Node Install
npm install event-pubsub

Browser Install
see browser examples above or below


Basic Example


NOTE - the only diffeence between node and browser code is how the events variable is created

  • node var events = new require('../../event-pubsub.js')();
  • browser var events = new window.pubsub();

Node

var events = new require('../../event-pubsub.js')();

events.on(
    'hello',
    function(data){
        console.log('hello event recieved ', data);
    }
);

events.on(
    '*',
    function(type){
        console.log('Catch all detected event type of : ',type, '. List of all the sent arguments ',arguments);
    }
);

events.on(
    'removeEvents',
    function(){
        events.off('*');
        console.log('Removed all events');
    }
);

/************************************\
 * trigger events for testing
 * **********************************/
events.trigger(
    'hello',
    'world'
);

events.trigger(
    'removeEvents'
);

Browser

HTML
<!DOCTYPE html>
<html>
    <head>
        <title>PubSub Example</title>
        <script src='../../event-pubsub-browser.js'></script>
        <script src='yourAmazingCode.js'></script>
    </head>
    <body>
        ...
    </body>
</html>
Inside Your Amazing Code
var events = new window.pubsub();

events.on(
    'hello',
    function(data){
        console.log('hello event recieved ', data);
    }
);

events.on(
    '*',
    function(type){
        console.log('Catch all detected event type of : ',type, '. List of all the sent arguments ',arguments);
    }
);

events.on(
    'removeEvents',
    function(){
        events.off('*');
        console.log('Removed all events');
    }
);

/************************************\
 * trigger events for testing
 * **********************************/
events.trigger(
    'hello',
    'world'
);

events.trigger(
    'removeEvents'
);