event-pubsub/README.md

125 lines
3.3 KiB
Markdown
Raw Normal View History

2014-02-18 21:55:53 -08:00
Event PubSub
2014-02-18 13:48:27 -08:00
============
2015-09-20 11:56:34 -07:00
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)
2015-09-20 11:56:34 -07:00
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)
2014-02-18 13:48:27 -08:00
Pubsub events for Node and the browser allowing event scoping and multiple scopes.
2014-02-18 21:55:53 -08:00
Easy for any developer level. No frills, just high speed pubsub events!
2014-02-27 16:08:12 -08:00
[Pretty GitHub.io site](http://riaevangelist.github.io/event-pubsub/)
2015-08-26 15:15:22 -07:00
[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*
2014-02-18 21:55:53 -08:00
---
### Basic Example
2014-02-18 21:55:53 -08:00
---
***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();``
2014-02-18 21:55:53 -08:00
#### Node
var events = new require('../../event-pubsub.js')();
events.on(
'hello',
function(data){
console.log('hello event recieved ', data);
}
);
2014-02-18 21:55:53 -08:00
events.on(
'*',
function(type){
console.log('Catch all detected event type of : ',type, '. List of all the sent arguments ',arguments);
}
);
2014-03-01 03:33:49 -08:00
events.on(
'removeEvents',
function(){
events.off('*','*');
2014-03-01 03:33:49 -08:00
console.log('Removed all events');
}
);
2014-02-18 21:55:53 -08:00
/************************************\
* trigger events for testing
* **********************************/
events.trigger(
'hello',
'world'
);
2014-03-01 03:33:49 -08:00
events.trigger(
'removeEvents'
);
2014-02-18 21:55:53 -08:00
#### 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();
2014-02-18 21:55:53 -08:00
events.on(
'hello',
function(data){
console.log('hello event recieved ', data);
}
);
2014-02-18 21:55:53 -08:00
events.on(
'*',
function(type){
console.log('Catch all detected event type of : ',type, '. List of all the sent arguments ',arguments);
}
);
2014-03-01 03:33:49 -08:00
events.on(
'removeEvents',
function(){
events.off('*','*');
2014-03-01 03:33:49 -08:00
console.log('Removed all events');
}
);
2014-02-18 21:55:53 -08:00
/************************************\
* trigger events for testing
* **********************************/
events.trigger(
'hello',
'world'
);
2014-03-01 03:33:49 -08:00
events.trigger(
'removeEvents'
);