event-pubsub
Advanced tools
Comparing version 4.2.3 to 4.2.4
@@ -12,4 +12,3 @@ 'use strict'; | ||
if(!handler){ | ||
const err=new ReferenceError('handler not defined.'); | ||
throw(err); | ||
throw new ReferenceError('handler not defined.'); | ||
} | ||
@@ -31,4 +30,3 @@ | ||
if(!handler){ | ||
var err=new ReferenceError('handler not defined. if you wish to remove all handlers from the event please pass "*" as the handler'); | ||
throw err; | ||
throw new ReferenceError('handler not defined. if you wish to remove all handlers from the event please pass "*" as the handler'); | ||
} | ||
@@ -35,0 +33,0 @@ |
72
es6.js
'use strict'; | ||
class EventPubSub { | ||
constructor(scope){ | ||
this._events_={}; | ||
this.publish=this.trigger=this.emit; | ||
this.subscribe=this.on; | ||
this.unSubscribe=this.off; | ||
constructor( scope ) { | ||
this._events_ = {}; | ||
this.publish = this.trigger = this.emit; | ||
this.subscribe = this.on; | ||
this.unSubscribe = this.off; | ||
} | ||
on(type,handler){ | ||
if(!handler){ | ||
const err=new ReferenceError('handler not defined.'); | ||
throw(err); | ||
on( type, handler ) { | ||
if ( !handler ) { | ||
throw new ReferenceError( 'handler not defined.' ); | ||
} | ||
if(!this._events_[type]){ | ||
this._events_[type]=[]; | ||
if ( !this._events_[ type ] ) { | ||
this._events_[ type ] = []; | ||
} | ||
this._events_[type].push(handler); | ||
this._events_[ type ].push( handler ); | ||
return this; | ||
} | ||
off(type,handler){ | ||
if(!this._events_[type]){ | ||
off( type, handler ) { | ||
if ( !this._events_[ type ] ) { | ||
return this; | ||
} | ||
if(!handler){ | ||
var err=new ReferenceError('handler not defined. if you wish to remove all handlers from the event please pass "*" as the handler'); | ||
throw err; | ||
if ( !handler ) { | ||
throw new ReferenceError( 'handler not defined. if you wish to remove all handlers from the event please pass "*" as the handler' ); | ||
} | ||
if(handler=='*'){ | ||
delete this._events_[type]; | ||
if ( handler == '*' ) { | ||
delete this._events_[ type ]; | ||
return this; | ||
} | ||
const handlers=this._events_[type]; | ||
const handlers = this._events_[ type ]; | ||
while(handlers.includes(handler)){ | ||
while ( handlers.includes( handler ) ) { | ||
handlers.splice( | ||
handlers.indexOf(handler), | ||
handlers.indexOf( handler ), | ||
1 | ||
@@ -49,4 +47,4 @@ ); | ||
if(handlers.length<1){ | ||
delete this._events_[type]; | ||
if ( handlers.length < 1 ) { | ||
delete this._events_[ type ]; | ||
} | ||
@@ -57,25 +55,25 @@ | ||
emit(type,...args){ | ||
if(!this._events_[type]){ | ||
return this.emit$(type,...args); | ||
emit( type, ...args ) { | ||
if ( !this._events_[ type ] ) { | ||
return this.emit$( type, ...args ); | ||
} | ||
const handlers=this._events_[type]; | ||
const handlers = this._events_[ type ]; | ||
for(let handler of handlers){ | ||
handler.apply(this, args); | ||
for ( let handler of handlers ) { | ||
handler.apply( this, args ); | ||
} | ||
return this.emit$(type,...args); | ||
return this.emit$( type, ...args ); | ||
} | ||
emit$(type,...args){ | ||
if(!this._events_['*']){ | ||
emit$( type, ...args ) { | ||
if ( !this._events_[ '*' ] ) { | ||
return this; | ||
} | ||
const catchAll=this._events_['*']; | ||
const catchAll = this._events_[ '*' ]; | ||
for(let handler of catchAll){ | ||
handler.call(this, type, ...args); | ||
for ( let handler of catchAll ) { | ||
handler.call( this, type, ...args ); | ||
} | ||
@@ -87,2 +85,2 @@ | ||
module.exports=EventPubSub; | ||
module.exports = EventPubSub; |
{ | ||
"name": "event-pubsub", | ||
"version": "4.2.3", | ||
"version": "4.2.4", | ||
"description": "Super light and fast Extensible PubSub events and EventEmitters for Node and the browser with support for ES6 by default, and ES5 versions for older verions of node and older IE/Safari versions. Easy for any developer level. No frills, just high speed pubsub events!", | ||
@@ -5,0 +5,0 @@ "main": "event-pubsub.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
0
20172
10
391