-
Notifications
You must be signed in to change notification settings - Fork 0
/
EventEmitter-compatible.min.js
8 lines (8 loc) · 6.37 KB
/
EventEmitter-compatible.min.js
1
2
3
4
5
6
7
8
/*!
* Event Emitter (the best you'll get ^^)
* author: Stefan Benicke
* version: 1.2.0
* url: https://github.com/opusonline/EventEmitter.js
* license: MIT
*/
!function(e,t){"use strict";function n(e,t,n){var r;Array.isArray(e)?(this.listener=e[0],r=e[1]):this.listener=e,this.listener.hasOwnProperty("boundThis")&&(r=this.listener.boundThis),this.context=r,this.namespaces=t,this.once=n||!1}function r(){}function s(e,t,r){var s,i=e.split(".");e=i.splice(0,1)[0],s=new n(t,i,r),"undefined"==typeof this._events&&(this._events={}),this._events.hasOwnProperty(e)===!1?this._events[e]=[s]:this._events[e].push(s),this._events.hasOwnProperty("newListener")&&this.emit("newListener",e,s)}function i(e,t,n,r){var s,i,o;for(s=0,i=this._events[e].length;i>s;s++)n(this._events[e][s],t,r)?(this._events.hasOwnProperty("removeListener")&&this.emit("removeListener",e,this._events[e][s]),delete this._events[e][s]):(o||(o=[]),o.push(this._events[e][s]));l(o)&&o.length>0?this._events[e]=o:delete this._events[e]}function o(e){var t,n;if("undefined"!=typeof e){for(t=0,n=this._events[e].length;n>t;t++)this.emit("removeListener",e,this._events[e][t]),delete this._events[e][t];delete this._events[e]}else for(e in this._events)this._events.hasOwnProperty(e)&&o.call(this,e)}function h(e,t){return f(t,e.namespaces)}function u(e,t,n){return(l(n)&&e.listener===n[0]&&e.context===n[1]||e.listener===n)&&f(t,e.namespaces)}function a(e,t){return e.once===!0&&f(t,e.namespaces)}function f(e,t){return l(e)?0===e.length?!0:0===t.length?!1:c(e,function(e){return p(t,e)>-1}):!0}function l(e){return Array.isArray?Array.isArray(e):"[object Array]"===Object.prototype.toString.call(e)}function p(e,t,n){var r,s,i,o;if(Array.prototype.indexOf)return Array.prototype.indexOf.call(e,t,n);if(null==e)throw new TypeError("array is null or not defined");if(s=Object(e),i=s.length>>>0,0===i)return-1;if(o=+n||0,Math.abs(o)===1/0&&(o=0),o>=i)return-1;for(r=Math.max(o>=0?o:i-Math.abs(o),0);i>r;){if(r in s&&s[r]===t)return r;r++}return-1}function c(e,t,n){var r,s,i,o,h,u;if(Array.prototype.every)return Array.prototype.every.call(e,t,n);if(null==e)throw new TypeError("array is null or not defined");if(i=Object(e),o=i.length>>>0,"function"!=typeof t)throw new TypeError;for(arguments.length>2&&(r=n),s=0;o>s;){if(s in i&&(h=i[s],u=t.call(r,h,s,i),!u))return!1;s++}return!0}function y(e,t,n){return String.prototype.includes?String.prototype.includes.call(e,t,n):-1!==String.prototype.indexOf.call(e,t,n)}function v(e,t){var n,r;if(!l(e))return e;if(l(t))for(n=0,r=t.length;r>n;n++)e.push(t[n]);else e.push(t);return e}var g,m=e.EventEmitter;r.noConflict=function(){return e.EventEmitter=m,r},r.inherits=function(e){e.super_=r,e.prototype=_(r.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}})},r.prototype.listeners=function(e){var t,n,r,s=[];if("undefined"==typeof this._events)return s;if(0===arguments.length||"undefined"==typeof e){for(e in this._events)if(this._events.hasOwnProperty(e))for(t=0,n=this._events[e].length;n>t;t++)s.push(this._events[e][t]);return s}if(arguments.length>1){for(t=0,n=arguments.length;n>t;t++)v(s,this.listeners.call(this,arguments[t]));return s}if(y(e,".")&&(r=e.split("."),e=r.splice(0,1)[0]),""===e){for(e in this._events)if(this._events.hasOwnProperty(e))for(t=0,n=this._events[e].length;n>t;t++)f(r,this._events[e][t].namespaces)&&s.push(this._events[e][t])}else{if(this._events.hasOwnProperty(e)===!1)return s;for(t=0,n=this._events[e].length;n>t;t++)f(r,this._events[e][t].namespaces)&&s.push(this._events[e][t])}return s},r.prototype.emit=function(e){var t,n,r,s,o;if("undefined"==typeof this._events||arguments.length<1||"undefined"==typeof e)return this;if(l(e)){for(r=0,s=e.length;s>r;r++)arguments[0]=e[r],this.emit.apply(this,arguments);return this}if(y(e,".")&&(o=e.split("."),e=o.splice(0,1)[0]),this._events.hasOwnProperty(e)===!1)return this;for(arguments.length>1&&(t=Array.prototype.slice.call(arguments,1)),r=0,s=this._events[e].length;s>r;r++)f(o,this._events[e][r].namespaces)&&(this._events[e][r].listener.apply(this._events[e][r].context,t),this._events[e][r].once&&(n=!0));return n&&i.call(this,e,o,a),this},r.prototype.on=function(e){var t,n;if(arguments.length<2||"undefined"==typeof e)return this;if(l(e)){for(t=0,n=e.length;n>t;t++)arguments[0]=e[t],this.on.apply(this,arguments);return this}for(t=1,n=arguments.length;n>t;t++)s.call(this,e,arguments[t]);return this},r.prototype.once=function(e){var t,n;if(arguments.length<2||"undefined"==typeof e)return this;if(l(e)){for(t=0,n=e.length;n>t;t++)arguments[0]=e[t],this.once.apply(this,arguments);return this}for(t=1,n=arguments.length;n>t;t++)s.call(this,e,arguments[t],!0);return this},r.prototype.off=function(e){var t,n,r;if("undefined"==typeof this._events)return this;if(0===arguments.length)this._events.hasOwnProperty("removeListener")?o.call(this):delete this._events;else{if("undefined"==typeof e)return this;if(l(e)){for(t=0,n=e.length;n>t;t++)arguments[0]=e[t],this.off.apply(this,arguments);return this}if(y(e,".")&&(r=e.split("."),e=r.splice(0,1)[0]),1===arguments.length)if(l(r))if(""===e)for(e in this._events)this._events.hasOwnProperty(e)&&i.call(this,e,r,h);else{if(this._events.hasOwnProperty(e)===!1)return this;i.call(this,e,r,h)}else{if(this._events.hasOwnProperty(e)===!1)return this;this._events.hasOwnProperty("removeListener")?o.call(this,e):delete this._events[e]}else if(""===e){for(e in this._events)if(this._events.hasOwnProperty(e))for(t=1,n=arguments.length;n>t;t++)i.call(this,e,r,u,arguments[t])}else{if(this._events.hasOwnProperty(e)===!1)return this;for(t=1,n=arguments.length;n>t;t++)i.call(this,e,r,u,arguments[t])}}return this},r.prototype.addListener=r.prototype.on,r.prototype.removeListener=r.prototype.off,r.prototype.removeAllListeners=r.prototype.off;var _=function(){function e(){}if(Object.create)return Object.create;var t=Object.prototype.hasOwnProperty;return function(n){if("object"!=typeof n)throw TypeError("Object prototype may only be an Object or null");e.prototype=n;var r=new e;if(e.prototype=null,arguments.length>1){var s=Object(arguments[1]);for(var i in s)t.call(s,i)&&(r[i]=s[i])}return r}}();Function.prototype.bind&&(g=Function.prototype.bind,Function.prototype.bind=function(e){var t=g.apply(this,arguments);return t.boundThis=e,t.boundArgs=Array.prototype.slice.call(arguments,1),t.targetFunction=this,t}),"function"==typeof define&&define.amd?define(function(){return r}):"undefined"!=typeof module?module.exports=r:e.EventEmitter=r}(this);