From 73d5ab559f9412b7db84c70d9596c234bf1dcd42 Mon Sep 17 00:00:00 2001 From: Brandon Miller Date: Wed, 23 Aug 2017 03:18:05 -0700 Subject: [PATCH] cleanup es6 fixes to es5 --- es5.js | 10 +++++++++- es6.js | 1 - examples/node/once.js | 8 +++++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/es5.js b/es5.js index 874fd1c..033c9d4 100644 --- a/es5.js +++ b/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; } diff --git a/es6.js b/es6.js index 2eff9e3..e9e859f 100644 --- a/es6.js +++ b/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); diff --git a/examples/node/once.js b/examples/node/once.js index 2e96c92..4a60b96 100644 --- a/examples/node/once.js +++ b/examples/node/once.js @@ -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-' +);