No description
Find a file
Brandon Nozaki Miller f0bd3b1f79 Update README.md
added links to examples and install information
2014-02-18 22:23:20 -08:00
examples added browser examples and seperated node examples 2014-02-18 21:36:21 -08:00
event-pubsub-browser.js added browser examples and seperated node examples 2014-02-18 21:36:21 -08:00
event-pubsub.js added initial files 2014-02-18 20:47:21 -08:00
LICENSE Initial commit 2014-02-18 13:48:27 -08:00
README.md Update README.md 2014-02-18 22:23:20 -08: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!

alt event-pubsub npm downloads

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

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

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

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