event-pubsub/examples/basic.js
2014-02-18 20:47:21 -08:00

57 lines
No EOL
1.1 KiB
JavaScript

var events = new require('../event-pubsub.js')();
/************************************\
*
* The events var was instantiated
* as it's own scope
*
* **********************************/
events.on(
'hello',
function(data){
console.log('hello event recieved ', data);
}
);
events.on(
'hello',
function(data){
console.log('Second handler listening to hello event got',data);
events.trigger(
'world',
{
type:'myObject',
data:{
x:'YAY, Objects!'
}
}
)
}
);
events.on(
'world',
function(data){
console.log('World event got',data);
}
);
/**********************************\
*
* Demonstrate * event (on all events)
* remove this for less verbose
* example
*
* ********************************/
events.on(
'*',
function(type){
console.log('Catch all detected event type of : ',type, '. List of all the sent arguments ',arguments);
}
);
events.trigger(
'hello',
'world'
);