mirror of
https://github.com/vale981/event-pubsub
synced 2025-03-04 17:11:38 -05:00
Fix for *,* or someEvent,* thanks to @hxsf and @conordickinson
This commit is contained in:
parent
af149485e2
commit
aa34d14485
2 changed files with 9 additions and 24 deletions
|
@ -19,28 +19,13 @@ function unsub(type,handler){
|
||||||
}
|
}
|
||||||
checkScope.apply(this);
|
checkScope.apply(this);
|
||||||
|
|
||||||
if(type=='*'){
|
if(handler=='*'){
|
||||||
var params=Array.prototype.slice.call(arguments,1);
|
delete this._events_[type];
|
||||||
for(
|
|
||||||
var keys = Object.keys(this._events_),
|
|
||||||
count = keys.length,
|
|
||||||
i=0;
|
|
||||||
i<count;
|
|
||||||
i++
|
|
||||||
){
|
|
||||||
params.unshift(keys[i]);
|
|
||||||
this.off.apply(this,params);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!this._events_[type])
|
if(!this._events_[type])
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(handler=='*'){
|
|
||||||
delete this._events_[type];
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(var i=0,
|
for(var i=0,
|
||||||
count=this._events_[type].length;
|
count=this._events_[type].length;
|
||||||
i<count;
|
i<count;
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
var events = new require('../../event-pubsub.js')();
|
var events = new require('../../event-pubsub.js')();
|
||||||
|
|
||||||
/************************************\
|
/************************************\
|
||||||
*
|
*
|
||||||
* The events var was instantiated
|
* The events var was instantiated
|
||||||
* as it's own scope
|
* as it's own scope
|
||||||
*
|
*
|
||||||
* **********************************/
|
* **********************************/
|
||||||
|
|
||||||
events.on(
|
events.on(
|
||||||
|
@ -23,7 +23,7 @@ events.on(
|
||||||
{
|
{
|
||||||
type:'myObject',
|
type:'myObject',
|
||||||
data:{
|
data:{
|
||||||
x:'YAY, Objects!'
|
x:'YAY, Objects!'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -34,17 +34,17 @@ events.on(
|
||||||
'world',
|
'world',
|
||||||
function(data){
|
function(data){
|
||||||
console.log('World event got',data);
|
console.log('World event got',data);
|
||||||
events.off('*');
|
events.off('*','*');
|
||||||
console.log('Removed all events');
|
console.log('Removed all events');
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
/**********************************\
|
/**********************************\
|
||||||
*
|
*
|
||||||
* Demonstrate * event (on all events)
|
* Demonstrate * event (on all events)
|
||||||
* remove this for less verbose
|
* remove this for less verbose
|
||||||
* example
|
* example
|
||||||
*
|
*
|
||||||
* ********************************/
|
* ********************************/
|
||||||
events.on(
|
events.on(
|
||||||
'*',
|
'*',
|
||||||
|
@ -59,4 +59,4 @@ events.on(
|
||||||
events.trigger(
|
events.trigger(
|
||||||
'hello',
|
'hello',
|
||||||
'world'
|
'world'
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Reference in a new issue