removing unused variable initializations in es6 and es5 files for errors

adding gitignore and npmignore files to avoid committing
This commit is contained in:
Val Vinder 2017-02-14 10:02:05 -08:00
parent eb96e92da5
commit 74d5410043
5 changed files with 39 additions and 150 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
npm-debug.log

1
.npmignore Normal file
View file

@ -0,0 +1 @@
examples/

6
es5.js
View file

@ -9,8 +9,7 @@ function EventPubSub() {
function on(type,handler){ function on(type,handler){
if(!handler){ if(!handler){
const err=new ReferenceError('handler not defined.'); throw new ReferenceError('handler not defined.');
throw(err);
} }
if(!this._events_[type]){ if(!this._events_[type]){
@ -27,8 +26,7 @@ function EventPubSub() {
} }
if(!handler){ 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 new ReferenceError('handler not defined. if you wish to remove all handlers from the event please pass "*" as the handler');
throw err;
} }
if(handler=='*'){ if(handler=='*'){

72
es6.js
View file

@ -1,85 +1,83 @@
'use strict'; 'use strict';
class EventPubSub { class EventPubSub {
constructor(scope){ constructor( scope ) {
this._events_={}; this._events_ = {};
this.publish=this.trigger=this.emit; this.publish = this.trigger = this.emit;
this.subscribe=this.on; this.subscribe = this.on;
this.unSubscribe=this.off; this.unSubscribe = this.off;
} }
on(type,handler){ on( type, handler ) {
if(!handler){ if ( !handler ) {
const err=new ReferenceError('handler not defined.'); throw new ReferenceError( 'handler not defined.' );
throw(err);
} }
if(!this._events_[type]){ if ( !this._events_[ type ] ) {
this._events_[type]=[]; this._events_[ type ] = [];
} }
this._events_[type].push(handler); this._events_[ type ].push( handler );
return this; return this;
} }
off(type,handler){ off( type, handler ) {
if(!this._events_[type]){ if ( !this._events_[ type ] ) {
return this; return this;
} }
if(!handler){ 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 new ReferenceError( 'handler not defined. if you wish to remove all handlers from the event please pass "*" as the handler' );
throw err;
} }
if(handler=='*'){ if ( handler == '*' ) {
delete this._events_[type]; delete this._events_[ type ];
return this; return this;
} }
const handlers=this._events_[type]; const handlers = this._events_[ type ];
while(handlers.includes(handler)){ while ( handlers.includes( handler ) ) {
handlers.splice( handlers.splice(
handlers.indexOf(handler), handlers.indexOf( handler ),
1 1
); );
} }
if(handlers.length<1){ if ( handlers.length < 1 ) {
delete this._events_[type]; delete this._events_[ type ];
} }
return this; return this;
} }
emit(type,...args){ emit( type, ...args ) {
if(!this._events_[type]){ if ( !this._events_[ type ] ) {
return this.emit$(type,...args); return this.emit$( type, ...args );
} }
const handlers=this._events_[type]; const handlers = this._events_[ type ];
for(let handler of handlers){ for ( let handler of handlers ) {
handler.apply(this, args); handler.apply( this, args );
} }
return this.emit$(type,...args); return this.emit$( type, ...args );
} }
emit$(type,...args){ emit$( type, ...args ) {
if(!this._events_['*']){ if ( !this._events_[ '*' ] ) {
return this; return this;
} }
const catchAll=this._events_['*']; const catchAll = this._events_[ '*' ];
for(let handler of catchAll){ for ( let handler of catchAll ) {
handler.call(this, type, ...args); handler.call( this, type, ...args );
} }
return this; return this;
} }
} }
module.exports=EventPubSub; module.exports = EventPubSub;

File diff suppressed because one or more lines are too long