mirror of
https://github.com/vale981/event-pubsub
synced 2025-03-04 17:11:38 -05:00
cleanup es6 fixes to es5
This commit is contained in:
parent
eb51b6e17b
commit
73d5ab559f
3 changed files with 16 additions and 3 deletions
10
es5.js
10
es5.js
|
@ -66,15 +66,23 @@ function EventPubSub() {
|
|||
arguments.splice(0,1);
|
||||
|
||||
var handlers=this._events_[type];
|
||||
var onceHandled=[];
|
||||
|
||||
for(var i in handlers){
|
||||
var handler=handlers[i];
|
||||
handler.apply(this, arguments);
|
||||
if(handler._once_){
|
||||
this.off(type,handler);
|
||||
onceHandled.push(handler);
|
||||
}
|
||||
}
|
||||
|
||||
for(var i in onceHandled){
|
||||
this.off(
|
||||
type,
|
||||
onceHandled[i]
|
||||
);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
1
es6.js
1
es6.js
|
@ -68,7 +68,6 @@ class EventPubSub {
|
|||
const onceHandled=[];
|
||||
|
||||
for ( let handler of handlers ) {
|
||||
console.log(handler)
|
||||
handler.apply( this, args );
|
||||
if(handler._once_){
|
||||
onceHandled.push(handler);
|
||||
|
|
|
@ -18,7 +18,8 @@ const events=new Events;
|
|||
'test.once',
|
||||
(data)=>{
|
||||
console.log(`got data ${data} from .on with true`)
|
||||
}
|
||||
},
|
||||
true
|
||||
);
|
||||
|
||||
/************************************\
|
||||
|
@ -28,3 +29,8 @@ events.emit(
|
|||
'test.once',
|
||||
'-TESTING-'
|
||||
);
|
||||
|
||||
events.emit(
|
||||
'test.once',
|
||||
'-NEVER SEE THIS-'
|
||||
);
|
||||
|
|
Loading…
Add table
Reference in a new issue