Comparing version 3.0.1 to 3.1.0
@@ -192,3 +192,3 @@ (function() { | ||
// Defining the list in which the handler should be inserted | ||
if (typeof event === 'string') { | ||
if (typeof event === 'string' || typeof event === 'symbol') { | ||
if (!this._handlers[event]) | ||
@@ -327,3 +327,4 @@ this._handlers[event] = []; | ||
// Variant 5 | ||
else if (arguments.length === 1 && typeof events === 'string') { | ||
else if (arguments.length === 1 && | ||
(typeof events === 'string' || typeof events === 'symbol')) { | ||
delete this._handlers[events]; | ||
@@ -518,3 +519,3 @@ } | ||
*/ | ||
Emitter.version = '3.0.1'; | ||
Emitter.version = '3.1.0'; | ||
@@ -521,0 +522,0 @@ |
/** | ||
* emmett - A custom event emitter for Node.js and the browser. | ||
* @version v3.0.1 | ||
* @version v3.1.0 | ||
* @link https://github.com/jacomyal/emmett | ||
* @license MIT | ||
*/ | ||
(function(){"use strict";function t(t,e){var n,r={};for(n in t)r[n]=t[n];for(n in e)r[n]=e[n];return r}function e(t){return!(!t||"object"!=typeof t||Array.isArray(t)||t instanceof Function||t instanceof RegExp)}function n(t,e){t=t||[];var n,r,s=[];for(r=0,n=t.length;n>r;r++)t[r].fn!==e&&s.push(t[r]);return s}var r={once:"boolean",scope:"object"},s=0,i=function(){this._enabled=!0,this.unbindAll()};i.prototype.unbindAll=function(){return this._handlers={},this._handlersAll=[],this._handlersComplex=[],this},i.prototype.on=function(t,n,i){var l,h,o,a,f,d,p;if(e(t)){for(a in t)this.on(a,t[a],n);return this}for("function"==typeof t&&(i=n,n=t,t=null),f=[].concat(t),l=0,h=f.length;h>l;l++){if(a=f[l],p={order:s++,fn:n},"string"==typeof a)this._handlers[a]||(this._handlers[a]=[]),d=this._handlers[a],p.type=a;else if(a instanceof RegExp)d=this._handlersComplex,p.pattern=a;else{if(null!==a)throw Error("Emitter.on: invalid event.");d=this._handlersAll}for(o in i||{})r[o]&&(p[o]=i[o]);d.push(p)}return this},i.prototype.once=function(){var n=Array.prototype.slice.call(arguments),r=n.length-1;return e(n[r])&&n.length>1?n[r]=t(n[r],{once:!0}):n.push({once:!0}),this.on.apply(this,n)},i.prototype.off=function(t,r){var s,i,l,h;if(1===arguments.length&&"function"==typeof t){r=arguments[0];for(l in this._handlers)this._handlers[l]=n(this._handlers[l],r),0===this._handlers[l].length&&delete this._handlers[l];this._handlersAll=n(this._handlersAll,r),this._handlersComplex=n(this._handlersComplex,r)}else if(1===arguments.length&&"string"==typeof t)delete this._handlers[t];else if(2===arguments.length){var o=[].concat(t);for(s=0,i=o.length;i>s;s++)h=o[s],this._handlers[h]=n(this._handlers[h],r),0===(this._handlers[h]||[]).length&&delete this._handlers[h]}else if(e(t))for(l in t)this.off(l,t[l]);return this},i.prototype.listeners=function(t){var e,n,r,s=this._handlersAll||[],i=!1;if(!t)throw Error("Emitter.listeners: no event provided.");for(s=s.concat(this._handlers[t]||[]),n=0,r=this._handlersComplex.length;r>n;n++)e=this._handlersComplex[n],~t.search(e.pattern)&&(i=!0,s.push(e));return this._handlersAll.length||i?s.sort(function(t,e){return t.order-e.order}):s.slice(0)},i.prototype.emit=function(t,n){if(!this._enabled)return this;if(e(t)){for(var r in t)this.emit(r,t[r]);return this}var s,i,l,h,o,a,f,d,p=[].concat(t),u=[];for(o=0,f=p.length;f>o;o++){for(l=this.listeners(p[o]),a=0,d=l.length;d>a;a++)h=l[a],s={type:p[o],target:this},arguments.length>1&&(s.data=n),h.fn.call("scope"in h?h.scope:this,s),h.once&&u.push(h);for(a=u.length-1;a>=0;a--)i=u[a].type?this._handlers[u[a].type]:u[a].pattern?this._handlersComplex:this._handlersAll,i.splice(i.indexOf(u[a]),1)}return this},i.prototype.kill=function(){this.unbindAll(),this._handlers=null,this._handlersAll=null,this._handlersComplex=null,this._enabled=!1,this.unbindAll=this.on=this.once=this.off=this.emit=this.listeners=Function.prototype},i.prototype.disable=function(){return this._enabled=!1,this},i.prototype.enable=function(){return this._enabled=!0,this},i.version="3.0.1","undefined"!=typeof exports?("undefined"!=typeof module&&module.exports&&(exports=module.exports=i),exports.Emitter=i):"function"==typeof define&&define.amd?define("emmett",[],function(){return i}):this.Emitter=i}).call(this); | ||
(function(){"use strict";function t(t,e){var n,r={};for(n in t)r[n]=t[n];for(n in e)r[n]=e[n];return r}function e(t){return!(!t||"object"!=typeof t||Array.isArray(t)||t instanceof Function||t instanceof RegExp)}function n(t,e){t=t||[];var n,r,s=[];for(r=0,n=t.length;n>r;r++)t[r].fn!==e&&s.push(t[r]);return s}var r={once:"boolean",scope:"object"},s=0,i=function(){this._enabled=!0,this.unbindAll()};i.prototype.unbindAll=function(){return this._handlers={},this._handlersAll=[],this._handlersComplex=[],this},i.prototype.on=function(t,n,i){var l,o,h,a,f,p,d;if(e(t)){for(a in t)this.on(a,t[a],n);return this}for("function"==typeof t&&(i=n,n=t,t=null),f=[].concat(t),l=0,o=f.length;o>l;l++){if(a=f[l],d={order:s++,fn:n},"string"==typeof a||"symbol"==typeof a)this._handlers[a]||(this._handlers[a]=[]),p=this._handlers[a],d.type=a;else if(a instanceof RegExp)p=this._handlersComplex,d.pattern=a;else{if(null!==a)throw Error("Emitter.on: invalid event.");p=this._handlersAll}for(h in i||{})r[h]&&(d[h]=i[h]);p.push(d)}return this},i.prototype.once=function(){var n=Array.prototype.slice.call(arguments),r=n.length-1;return e(n[r])&&n.length>1?n[r]=t(n[r],{once:!0}):n.push({once:!0}),this.on.apply(this,n)},i.prototype.off=function(t,r){var s,i,l,o;if(1===arguments.length&&"function"==typeof t){r=arguments[0];for(l in this._handlers)this._handlers[l]=n(this._handlers[l],r),0===this._handlers[l].length&&delete this._handlers[l];this._handlersAll=n(this._handlersAll,r),this._handlersComplex=n(this._handlersComplex,r)}else if(1!==arguments.length||"string"!=typeof t&&"symbol"!=typeof t){if(2===arguments.length){var h=[].concat(t);for(s=0,i=h.length;i>s;s++)o=h[s],this._handlers[o]=n(this._handlers[o],r),0===(this._handlers[o]||[]).length&&delete this._handlers[o]}else if(e(t))for(l in t)this.off(l,t[l])}else delete this._handlers[t];return this},i.prototype.listeners=function(t){var e,n,r,s=this._handlersAll||[],i=!1;if(!t)throw Error("Emitter.listeners: no event provided.");for(s=s.concat(this._handlers[t]||[]),n=0,r=this._handlersComplex.length;r>n;n++)e=this._handlersComplex[n],~t.search(e.pattern)&&(i=!0,s.push(e));return this._handlersAll.length||i?s.sort(function(t,e){return t.order-e.order}):s.slice(0)},i.prototype.emit=function(t,n){if(!this._enabled)return this;if(e(t)){for(var r in t)this.emit(r,t[r]);return this}var s,i,l,o,h,a,f,p,d=[].concat(t),u=[];for(h=0,f=d.length;f>h;h++){for(l=this.listeners(d[h]),a=0,p=l.length;p>a;a++)o=l[a],s={type:d[h],target:this},arguments.length>1&&(s.data=n),o.fn.call("scope"in o?o.scope:this,s),o.once&&u.push(o);for(a=u.length-1;a>=0;a--)i=u[a].type?this._handlers[u[a].type]:u[a].pattern?this._handlersComplex:this._handlersAll,i.splice(i.indexOf(u[a]),1)}return this},i.prototype.kill=function(){this.unbindAll(),this._handlers=null,this._handlersAll=null,this._handlersComplex=null,this._enabled=!1,this.unbindAll=this.on=this.once=this.off=this.emit=this.listeners=Function.prototype},i.prototype.disable=function(){return this._enabled=!1,this},i.prototype.enable=function(){return this._enabled=!0,this},i.version="3.1.0","undefined"!=typeof exports?("undefined"!=typeof module&&module.exports&&(exports=module.exports=i),exports.Emitter=i):"function"==typeof define&&define.amd?define("emmett",[],function(){return i}):this.Emitter=i}).call(this); |
{ | ||
"name": "emmett", | ||
"version": "3.0.1", | ||
"version": "3.1.0", | ||
"description": "A custom event emitter for Node.js and the browser.", | ||
@@ -5,0 +5,0 @@ "main": "emmett.js", |
@@ -61,2 +61,6 @@ # Emmett | ||
// Using ES6 symbol as event name | ||
const sym = Symbol(); | ||
emitter.on(sym, callback); | ||
// Matching event names with a regex | ||
@@ -63,0 +67,0 @@ emitter.on(/^event/, callback); |
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
22070
459
189