mirror of
https://github.com/vale981/event-pubsub
synced 2025-03-05 09:31:42 -05:00
added ability to remove all events
This commit is contained in:
parent
92fdce30c6
commit
6c930f9283
3 changed files with 0 additions and 205 deletions
|
@ -1,57 +0,0 @@
|
|||
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'
|
||||
);
|
|
@ -1,90 +0,0 @@
|
|||
var pubsub = require('../event-pubsub.js');
|
||||
|
||||
/************************************\
|
||||
* instantiating myEvents scope
|
||||
* **********************************/
|
||||
var myEvents=new pubsub();
|
||||
|
||||
/************************************\
|
||||
* instantiating myEvents2 scope
|
||||
* **********************************/
|
||||
var myEvents2=new pubsub();
|
||||
|
||||
|
||||
/************************************\
|
||||
* binding myEvents events
|
||||
* **********************************/
|
||||
myEvents.on(
|
||||
'hello',
|
||||
function(data){
|
||||
console.log('myEvents hello event recieved ', data);
|
||||
}
|
||||
);
|
||||
|
||||
myEvents.on(
|
||||
'hello',
|
||||
function(data){
|
||||
console.log('Second handler listening to myEvents hello event got',data);
|
||||
myEvents.trigger(
|
||||
'world',
|
||||
{
|
||||
type:'myObject',
|
||||
data:{
|
||||
x:'YAY, Objects!'
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
);
|
||||
|
||||
myEvents.on(
|
||||
'world',
|
||||
function(data){
|
||||
console.log('myEvents World event got',data);
|
||||
}
|
||||
);
|
||||
|
||||
/**********************************\
|
||||
*
|
||||
* Demonstrate * event (on all events)
|
||||
* remove this for less verbose
|
||||
* example
|
||||
*
|
||||
* ********************************/
|
||||
myEvents.on(
|
||||
'*',
|
||||
function(type){
|
||||
console.log('myEvents Catch all detected event type of : ',type, '. List of all the sent arguments ',arguments);
|
||||
}
|
||||
);
|
||||
|
||||
/************************************\
|
||||
* binding myEvents2 events
|
||||
* **********************************/
|
||||
myEvents2.on(
|
||||
'hello',
|
||||
function(data){
|
||||
console.log('myEvents2 Hello event should never be called ', data);
|
||||
}
|
||||
);
|
||||
|
||||
myEvents2.on(
|
||||
'world',
|
||||
function(data){
|
||||
console.log('myEvents2 World event ',data);
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
/************************************\
|
||||
* trigger events for testing
|
||||
* **********************************/
|
||||
myEvents.trigger(
|
||||
'hello',
|
||||
'world'
|
||||
);
|
||||
|
||||
myEvents2.trigger(
|
||||
'world',
|
||||
'is round'
|
||||
);
|
|
@ -1,58 +0,0 @@
|
|||
var pubsub = require('../event-pubsub.js');
|
||||
|
||||
/************************************\
|
||||
*
|
||||
* The events var was instantiated
|
||||
* as it's own scope
|
||||
*
|
||||
* **********************************/
|
||||
|
||||
var thing={
|
||||
id:'my thing'
|
||||
}
|
||||
/******************************\
|
||||
*
|
||||
* Create events in the scope
|
||||
* of the "thing" object
|
||||
*
|
||||
* ****************************/
|
||||
new pubsub(thing);
|
||||
|
||||
console.log(thing);
|
||||
|
||||
thing.on(
|
||||
'getID',
|
||||
function(){
|
||||
console.log('things id is : ',this.id);
|
||||
}
|
||||
);
|
||||
|
||||
thing.on(
|
||||
'setID',
|
||||
function(id){
|
||||
console.log('setting id to : ',id);
|
||||
this.id=id;
|
||||
this.trigger('getID');
|
||||
}
|
||||
);
|
||||
|
||||
/**********************************\
|
||||
*
|
||||
* Demonstrate * event (on all events)
|
||||
* remove this for less verbose
|
||||
* example
|
||||
*
|
||||
* ********************************/
|
||||
thing.on(
|
||||
'*',
|
||||
function(type){
|
||||
console.log('Catch all detected event type of : ',type, '. List of all the sent arguments ',arguments);
|
||||
}
|
||||
);
|
||||
|
||||
thing.trigger('getID');
|
||||
|
||||
thing.trigger(
|
||||
'setID',
|
||||
'your thing'
|
||||
)
|
Loading…
Add table
Reference in a new issue