Package Exports
- event-pubsub
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (event-pubsub) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Event PubSub
npm info :
GitHub info :
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!
See NPM stats for event-pubsub
EXAMPLE FILES
Node Installnpm 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'
);