Skip to content

Commit

Permalink
Merge pull request #12 from mrvini/master
Browse files Browse the repository at this point in the history
Removing unused variables initializations thanks @mrvini
  • Loading branch information
RIAEvangelist authored Feb 15, 2017
2 parents eb96e92 + 52c17cf commit c8b1930
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 151 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npm-debug.log
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
examples/
6 changes: 2 additions & 4 deletions es5.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ function EventPubSub() {

function on(type,handler){
if(!handler){
const err=new ReferenceError('handler not defined.');
throw(err);
throw new ReferenceError('handler not defined.');
}

if(!this._events_[type]){
Expand All @@ -27,8 +26,7 @@ function EventPubSub() {
}

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');
}

if(handler=='*'){
Expand Down
72 changes: 35 additions & 37 deletions es6.js
Original file line number Diff line number Diff line change
@@ -1,85 +1,83 @@
'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
);
}

if(handlers.length<1){
delete this._events_[type];
if ( handlers.length < 1 ) {
delete this._events_[ type ];
}

return this;
}

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 );
}

return this;
}
}

module.exports=EventPubSub;
module.exports = EventPubSub;
109 changes: 0 additions & 109 deletions npm-debug.log

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"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!",
"main": "event-pubsub.js",
"directories": {
Expand Down

0 comments on commit c8b1930

Please sign in to comment.