mirror of
https://github.com/vale981/event-pubsub
synced 2025-03-04 17:11:38 -05:00
working on issue #7
This commit is contained in:
parent
101ec4f84e
commit
5379ac2a90
4 changed files with 28 additions and 10 deletions
13
es5.js
13
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;
|
||||
}
|
||||
|
|
6
es6.js
6
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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue