2014-02-22 20:13:31 +11:00
|
|
|
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);
|
2014-03-01 23:13:06 +11:00
|
|
|
events.off('*');
|
|
|
|
console.log('Removed all events');
|
2014-02-22 20:13:31 +11:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
/**********************************\
|
|
|
|
*
|
|
|
|
* 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);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
/************************************\
|
|
|
|
* trigger events for testing
|
|
|
|
* **********************************/
|
|
|
|
events.trigger(
|
|
|
|
'hello',
|
|
|
|
'world'
|
|
|
|
);
|