mirror of
https://github.com/vale981/event-pubsub
synced 2025-03-05 09:31:42 -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.publish=this.trigger=this.emit=emit;
|
||||||
this.subscribe=this.on=on;
|
this.subscribe=this.on=on;
|
||||||
this.unSubscribe=this.off=off;
|
this.unSubscribe=this.off=off;
|
||||||
|
this.emit$=emit$;
|
||||||
|
|
||||||
function on(type,handler){
|
function on(type,handler){
|
||||||
if(!handler){
|
if(!handler){
|
||||||
|
@ -52,19 +53,23 @@ function EventPubSub() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function emit(type){
|
function emit(type){
|
||||||
if(!this._events_[type]){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
arguments.splice=Array.prototype.splice;
|
arguments.splice=Array.prototype.splice;
|
||||||
arguments.splice(0,1);
|
arguments.splice(0,1);
|
||||||
|
|
||||||
|
if(!this._events_[type]){
|
||||||
|
return this.emit$.apply(this, type, arguments);
|
||||||
|
}
|
||||||
|
|
||||||
const handlers=this._events_[type];
|
const handlers=this._events_[type];
|
||||||
|
|
||||||
for(let handler of handlers){
|
for(let handler of handlers){
|
||||||
handler.apply(this, arguments);
|
handler.apply(this, arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return this.emit$.apply(this, type, arguments);
|
||||||
|
}
|
||||||
|
|
||||||
|
function emit$(type, args){
|
||||||
if(!this._events_['*']){
|
if(!this._events_['*']){
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
6
es6.js
6
es6.js
|
@ -55,7 +55,7 @@ class EventPubSub {
|
||||||
|
|
||||||
emit(type,...args){
|
emit(type,...args){
|
||||||
if(!this._events_[type]){
|
if(!this._events_[type]){
|
||||||
return;
|
return this.emit$(type,...args);
|
||||||
}
|
}
|
||||||
|
|
||||||
const handlers=this._events_[type];
|
const handlers=this._events_[type];
|
||||||
|
@ -64,6 +64,10 @@ class EventPubSub {
|
||||||
handler.apply(this, args);
|
handler.apply(this, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return this.emit$(type,...args);
|
||||||
|
}
|
||||||
|
|
||||||
|
emit$(type,...args){
|
||||||
if(!this._events_['*']){
|
if(!this._events_['*']){
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ window.EventPubSub=function EventPubSub() {
|
||||||
this.publish=this.trigger=this.emit=emit;
|
this.publish=this.trigger=this.emit=emit;
|
||||||
this.subscribe=this.on=on;
|
this.subscribe=this.on=on;
|
||||||
this.unSubscribe=this.off=off;
|
this.unSubscribe=this.off=off;
|
||||||
|
this.emit$=emit$;
|
||||||
|
|
||||||
function on(type,handler){
|
function on(type,handler){
|
||||||
if(!handler){
|
if(!handler){
|
||||||
|
@ -52,19 +53,23 @@ window.EventPubSub=function EventPubSub() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function emit(type){
|
function emit(type){
|
||||||
if(!this._events_[type]){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
arguments.splice=Array.prototype.splice;
|
arguments.splice=Array.prototype.splice;
|
||||||
arguments.splice(0,1);
|
arguments.splice(0,1);
|
||||||
|
|
||||||
|
if(!this._events_[type]){
|
||||||
|
return emit$.apply(this, type, arguments);
|
||||||
|
}
|
||||||
|
|
||||||
const handlers=this._events_[type];
|
const handlers=this._events_[type];
|
||||||
|
|
||||||
for(let handler of handlers){
|
for(let handler of handlers){
|
||||||
handler.apply(this, arguments);
|
handler.apply(this, arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return emit$.apply(this, type, arguments);
|
||||||
|
}
|
||||||
|
|
||||||
|
function emit$(type, args){
|
||||||
if(!this._events_['*']){
|
if(!this._events_['*']){
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ window.EventPubSub=class EventPubSub {
|
||||||
|
|
||||||
emit(type,...args){
|
emit(type,...args){
|
||||||
if(!this._events_[type]){
|
if(!this._events_[type]){
|
||||||
return;
|
return this.emit$(type,...args);
|
||||||
}
|
}
|
||||||
|
|
||||||
const handlers=this._events_[type];
|
const handlers=this._events_[type];
|
||||||
|
@ -64,6 +64,10 @@ window.EventPubSub=class EventPubSub {
|
||||||
handler.apply(this, args);
|
handler.apply(this, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return this.emit$(type,...args);
|
||||||
|
}
|
||||||
|
|
||||||
|
emit$(type,...args){
|
||||||
if(!this._events_['*']){
|
if(!this._events_['*']){
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue