From 5379ac2a90f3a6a1a8d247beafb79996ba8e0613 Mon Sep 17 00:00:00 2001 From: SSMP Date: Wed, 5 Oct 2016 12:02:04 -0700 Subject: [PATCH] working on issue #7 --- es5.js | 13 +++++++++---- es6.js | 6 +++++- event-pubsub-browser-es5.js | 13 +++++++++---- event-pubsub-browser.js | 6 +++++- 4 files changed, 28 insertions(+), 10 deletions(-) diff --git a/es5.js b/es5.js index 782ed84..638c9f6 100644 --- a/es5.js +++ b/es5.js @@ -5,6 +5,7 @@ function EventPubSub() { this.publish=this.trigger=this.emit=emit; this.subscribe=this.on=on; this.unSubscribe=this.off=off; + this.emit$=emit$; function on(type,handler){ if(!handler){ @@ -52,19 +53,23 @@ function EventPubSub() { } function emit(type){ - if(!this._events_[type]){ - return; - } - arguments.splice=Array.prototype.splice; arguments.splice(0,1); + if(!this._events_[type]){ + return this.emit$.apply(this, type, arguments); + } + const handlers=this._events_[type]; for(let handler of handlers){ handler.apply(this, arguments); } + return this.emit$.apply(this, type, arguments); + } + + function emit$(type, args){ if(!this._events_['*']){ return this; } diff --git a/es6.js b/es6.js index e52a1af..a2e70af 100644 --- a/es6.js +++ b/es6.js @@ -55,7 +55,7 @@ class EventPubSub { emit(type,...args){ if(!this._events_[type]){ - return; + return this.emit$(type,...args); } const handlers=this._events_[type]; @@ -64,6 +64,10 @@ class EventPubSub { handler.apply(this, args); } + return this.emit$(type,...args); + } + + emit$(type,...args){ if(!this._events_['*']){ return this; } diff --git a/event-pubsub-browser-es5.js b/event-pubsub-browser-es5.js index e348169..99ea1db 100644 --- a/event-pubsub-browser-es5.js +++ b/event-pubsub-browser-es5.js @@ -5,6 +5,7 @@ window.EventPubSub=function EventPubSub() { this.publish=this.trigger=this.emit=emit; this.subscribe=this.on=on; this.unSubscribe=this.off=off; + this.emit$=emit$; function on(type,handler){ if(!handler){ @@ -52,19 +53,23 @@ window.EventPubSub=function EventPubSub() { } function emit(type){ - if(!this._events_[type]){ - return; - } - arguments.splice=Array.prototype.splice; arguments.splice(0,1); + if(!this._events_[type]){ + return emit$.apply(this, type, arguments); + } + const handlers=this._events_[type]; for(let handler of handlers){ handler.apply(this, arguments); } + return emit$.apply(this, type, arguments); + } + + function emit$(type, args){ if(!this._events_['*']){ return this; } diff --git a/event-pubsub-browser.js b/event-pubsub-browser.js index e43b43b..ff9f56b 100644 --- a/event-pubsub-browser.js +++ b/event-pubsub-browser.js @@ -55,7 +55,7 @@ window.EventPubSub=class EventPubSub { emit(type,...args){ if(!this._events_[type]){ - return; + return this.emit$(type,...args); } const handlers=this._events_[type]; @@ -64,6 +64,10 @@ window.EventPubSub=class EventPubSub { handler.apply(this, args); } + return this.emit$(type,...args); + } + + emit$(type,...args){ if(!this._events_['*']){ return this; }