eventemitter2
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -271,40 +271,39 @@ /*! | ||
if (type === 'newListener' && !this.newListener) { | ||
if (!this._events.newListener) { return false; } | ||
if (!this._events.newListener) { | ||
return false; | ||
} | ||
} | ||
// Loop through the *_all* functions and invoke them. | ||
var al = arguments.length; | ||
var args,l,i,j; | ||
var handler; | ||
if (this._all) { | ||
var l = arguments.length; | ||
var args = new Array(l - 1); | ||
for (var i = 1; i < l; i++) args[i - 1] = arguments[i]; | ||
if (al > 3) { | ||
args = new Array(al); | ||
for (j = 1; j < al; j++) args[j] = arguments[j]; | ||
} | ||
for (i = 0, l = this._all.length; i < l; i++) { | ||
this.event = type; | ||
this._all[i].apply(this, [type].concat(args)); | ||
} | ||
} | ||
// If there is no 'error' event listener then throw. | ||
if (type === 'error') { | ||
if (!this._all && | ||
!this._events.error && | ||
!(this.wildcard && this.listenerTree.error)) { | ||
if (arguments[1] instanceof Error) { | ||
throw arguments[1]; // Unhandled 'error' event | ||
} else { | ||
throw new Error("Uncaught, unspecified 'error' event."); | ||
switch (al) { | ||
case 1: | ||
this._all[i].call(this, type); | ||
break; | ||
case 2: | ||
this._all[i].call(this, type, arguments[1]); | ||
break; | ||
case 3: | ||
this._all[i].call(this, type, arguments[1], arguments[2]); | ||
break; | ||
default: | ||
this._all[i].apply(this, args); | ||
} | ||
return false; | ||
} | ||
} | ||
var handler; | ||
if(this.wildcard) { | ||
if (this.wildcard) { | ||
handler = []; | ||
var ns = typeof type === 'string' ? type.split(this.delimiter) : type.slice(); | ||
searchListenerTree.call(this, handler, ns, this.listenerTree, 0); | ||
} | ||
else { | ||
} else { | ||
handler = this._events[type]; | ||
@@ -315,38 +314,49 @@ } | ||
this.event = type; | ||
if (arguments.length === 1) { | ||
switch (al) { | ||
case 1: | ||
handler.call(this); | ||
break; | ||
case 2: | ||
handler.call(this, arguments[1]); | ||
break; | ||
case 3: | ||
handler.call(this, arguments[1], arguments[2]); | ||
break; | ||
default: | ||
args = new Array(al - 1); | ||
for (j = 1; j < al; j++) args[j - 1] = arguments[j]; | ||
handler.apply(this, args); | ||
} | ||
else if (arguments.length > 1) | ||
switch (arguments.length) { | ||
case 2: | ||
handler.call(this, arguments[1]); | ||
break; | ||
case 3: | ||
handler.call(this, arguments[1], arguments[2]); | ||
break; | ||
// slower | ||
default: | ||
var l = arguments.length; | ||
var args = new Array(l - 1); | ||
for (var i = 1; i < l; i++) args[i - 1] = arguments[i]; | ||
handler.apply(this, args); | ||
} | ||
return true; | ||
} | ||
else if (handler) { | ||
var l = arguments.length; | ||
var args = new Array(l - 1); | ||
for (var i = 1; i < l; i++) args[i - 1] = arguments[i]; | ||
var listeners = handler.slice(); | ||
for (var i = 0, l = listeners.length; i < l; i++) { | ||
} else if (handler && handler.length) { | ||
if (al > 3) { | ||
args = new Array(al - 1); | ||
for (j = 1; j < al; j++) args[j - 1] = arguments[j]; | ||
} | ||
for (i = 0, l = handler.length; i < l; i++) { | ||
this.event = type; | ||
listeners[i].apply(this, args); | ||
switch (al) { | ||
case 1: | ||
handler[i].call(this); | ||
break; | ||
case 2: | ||
handler[i].call(this, arguments[1]); | ||
break; | ||
case 3: | ||
handler[i].call(this, arguments[1], arguments[2]); | ||
break; | ||
default: | ||
handler[i].apply(this, args); | ||
} | ||
} | ||
return (listeners.length > 0) || !!this._all; | ||
} else if (!this._all && type === 'error') { | ||
if (arguments[1] instanceof Error) { | ||
throw arguments[1]; // Unhandled 'error' event | ||
} else { | ||
throw new Error("Uncaught, unspecified 'error' event."); | ||
} | ||
return false; | ||
} | ||
else { | ||
return !!this._all; | ||
} | ||
return !!this._all; | ||
}; | ||
@@ -361,3 +371,3 @@ | ||
if (type === 'newListener' && !this.newListener) { | ||
if (!this._events.newListener) { return Promise.resolve([false]); } | ||
if (!this._events.newListener) { return Promise.resolve([false]); } | ||
} | ||
@@ -367,24 +377,25 @@ | ||
// Loop through the *_all* functions and invoke them. | ||
var al = arguments.length; | ||
var args,l,i,j; | ||
var handler; | ||
if (this._all) { | ||
var l = arguments.length; | ||
var args = new Array(l - 1); | ||
for (var i = 1; i < l; i++) args[i - 1] = arguments[i]; | ||
if (al > 3) { | ||
args = new Array(al); | ||
for (j = 1; j < al; j++) args[j] = arguments[j]; | ||
} | ||
for (i = 0, l = this._all.length; i < l; i++) { | ||
this.event = type; | ||
promises.push(this._all[i].apply(this, args)); | ||
} | ||
} | ||
// If there is no 'error' event listener then throw. | ||
if (type === 'error') { | ||
if (!this._all && | ||
!this._events.error && | ||
!(this.wildcard && this.listenerTree.error)) { | ||
if (arguments[1] instanceof Error) { | ||
return Promise.reject(arguments[1]); // Unhandled 'error' event | ||
} else { | ||
return Promise.reject("Uncaught, unspecified 'error' event."); | ||
switch (al) { | ||
case 1: | ||
promises.push(this._all[i].call(this, type)); | ||
break; | ||
case 2: | ||
promises.push(this._all[i].call(this, type, arguments[1])); | ||
break; | ||
case 3: | ||
promises.push(this._all[i].call(this, type, arguments[1], arguments[2])); | ||
break; | ||
default: | ||
promises.push(this._all[i].apply(this, args)); | ||
} | ||
@@ -394,10 +405,7 @@ } | ||
var handler; | ||
if(this.wildcard) { | ||
if (this.wildcard) { | ||
handler = []; | ||
var ns = typeof type === 'string' ? type.split(this.delimiter) : type.slice(); | ||
searchListenerTree.call(this, handler, ns, this.listenerTree, 0); | ||
} | ||
else { | ||
} else { | ||
handler = this._events[type]; | ||
@@ -408,33 +416,46 @@ } | ||
this.event = type; | ||
if (arguments.length === 1) { | ||
switch (al) { | ||
case 1: | ||
promises.push(handler.call(this)); | ||
break; | ||
case 2: | ||
promises.push(handler.call(this, arguments[1])); | ||
break; | ||
case 3: | ||
promises.push(handler.call(this, arguments[1], arguments[2])); | ||
break; | ||
default: | ||
args = new Array(al - 1); | ||
for (j = 1; j < al; j++) args[j - 1] = arguments[j]; | ||
promises.push(handler.apply(this, args)); | ||
} | ||
else if (arguments.length > 1) { | ||
switch (arguments.length) { | ||
case 2: | ||
promises.push(handler.call(this, arguments[1])); | ||
break; | ||
case 3: | ||
promises.push(handler.call(this, arguments[1], arguments[2])); | ||
break; | ||
// slower | ||
default: | ||
var l = arguments.length; | ||
var args = new Array(l - 1); | ||
for (var i = 1; i < l; i++) args[i - 1] = arguments[i]; | ||
promises.push(handler.apply(this, args)); | ||
} else if (handler && handler.length) { | ||
if (al > 3) { | ||
args = new Array(al - 1); | ||
for (j = 1; j < al; j++) args[j - 1] = arguments[j]; | ||
} | ||
for (i = 0, l = handler.length; i < l; i++) { | ||
this.event = type; | ||
switch (al) { | ||
case 1: | ||
promises.push(handler[i].call(this)); | ||
break; | ||
case 2: | ||
promises.push(handler[i].call(this, arguments[1])); | ||
break; | ||
case 3: | ||
promises.push(handler[i].call(this, arguments[1], arguments[2])); | ||
break; | ||
default: | ||
promises.push(handler[i].apply(this, args)); | ||
} | ||
} | ||
} else if (!this._all && type === 'error') { | ||
if (arguments[1] instanceof Error) { | ||
return Promise.reject(arguments[1]); // Unhandled 'error' event | ||
} else { | ||
return Promise.reject("Uncaught, unspecified 'error' event."); | ||
} | ||
} | ||
else if (handler) { | ||
var l = arguments.length; | ||
var args = new Array(l - 1); | ||
for (var i = 1; i < l; i++) args[i - 1] = arguments[i]; | ||
var listeners = handler.slice(); | ||
for (var i = 0, l = listeners.length; i < l; i++) { | ||
this.event = type; | ||
promises.push(listeners[i].apply(this, args)); | ||
} | ||
} | ||
return Promise.all(promises); | ||
@@ -571,5 +592,5 @@ }; | ||
} | ||
this.emit("removeListener", type, listener); | ||
return this; | ||
@@ -586,3 +607,3 @@ } | ||
} | ||
this.emit("removeListener", type, listener); | ||
@@ -589,0 +610,0 @@ } |
{ | ||
"name": "eventemitter2", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "A Node.js event emitter implementation with namespaces, wildcards, TTL and browser support.", | ||
@@ -5,0 +5,0 @@ "keywords": ["event", "events", "emitter", "eventemitter"], |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
31810
612
0