event-pubsub/README.md
2016-07-11 08:38:08 -07:00

124 lines
3.3 KiB
Markdown

Event PubSub
============
npm info :
![event-pubsub npm version](https://img.shields.io/npm/v/event-pubsub.svg) ![total npm downloads for event-pubsub](https://img.shields.io/npm/dt/event-pubsub.svg) ![monthly npm downloads for event-pubsub](https://img.shields.io/npm/dm/event-pubsub.svg)
GitHub info :
![event-pubsub GitHub Release](https://img.shields.io/github/release/RIAEvangelist/event-pubsub.svg) ![GitHub license event-pubsub license](https://img.shields.io/github/license/RIAEvangelist/event-pubsub.svg) ![open issues for event-pubsub on GitHub](https://img.shields.io/github/issues/RIAEvangelist/event-pubsub.svg)
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](http://riaevangelist.github.io/event-pubsub/)
[See NPM stats for event-pubsub](http://npm-stat.com/charts.html?package=event-pubsub&author=&from=&to=)
**EXAMPLE FILES**
1. [Node Pubsub Event Examples](https://github.com/RIAEvangelist/event-pubsub/tree/master/examples/node)
2. [Browser Pubsub Event Examples](https://github.com/RIAEvangelist/event-pubsub/tree/master/examples/browser)
**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'
);