mirror of
https://github.com/vale981/event-pubsub
synced 2025-03-04 17:11:38 -05:00
fixed memory leak related to event removal
This commit is contained in:
parent
ebe179e566
commit
4cacd8a919
2 changed files with 16 additions and 7 deletions
|
@ -34,13 +34,18 @@ window.pubsub=(
|
|||
return;
|
||||
}
|
||||
|
||||
if(this._events_[type].length<2){
|
||||
delete this._events_[type];
|
||||
return;
|
||||
}
|
||||
|
||||
for(var i=0,
|
||||
count=this._events_[type].length;
|
||||
count=this._events_[type].length;
|
||||
i<count;
|
||||
i++){
|
||||
|
||||
if(this._events_[type][i]==handler)
|
||||
delete this._events_[type][i];
|
||||
i++
|
||||
){
|
||||
if(this._events_[type][i]==handler)
|
||||
this._events_[type].splice(i,1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,6 @@ function unsub(type,handler){
|
|||
checkScope.apply(this);
|
||||
|
||||
if(type=='*'){
|
||||
delete this._events_['*'];
|
||||
for(
|
||||
var keys = Object.keys(this._events_),
|
||||
count = keys.length,
|
||||
|
@ -31,13 +30,18 @@ function unsub(type,handler){
|
|||
return;
|
||||
}
|
||||
|
||||
if(this._events_[type].length<2){
|
||||
delete this._events_[type];
|
||||
return;
|
||||
}
|
||||
|
||||
for(var i=0,
|
||||
count=this._events_[type].length;
|
||||
i<count;
|
||||
i++
|
||||
){
|
||||
if(this._events_[type][i]==handler)
|
||||
delete this._events_[type][i];
|
||||
this._events_[type].splice(i,1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue