Liferay.Loader.define("frontend-js-web@5.0.31/liferay/events/EventEmitter",["module","exports","require","./Disposable","./EventHandle"],(function(e,t,s){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var n=i(s("./Disposable")),r=i(s("./EventHandle"));function i(e){return e&&e.__esModule?e:{default:e}}const e=[0];class h extends n.default{constructor(){super(),this._events=null,this._listenerHandlers=null,this._shouldUseFacade=!1}_addHandler(e,t){return e?(Array.isArray(e)||(e=[e]),e.push(t)):e=t,e}addListener(e,t,s){this._validateListener(t);const n=this._toEventsArray(e);for(let e=0;e<n.length;e++)this._addSingleListener(n[e],t,s);return new r.default(this,e,t)}_addSingleListener(e,t,s,n){this._runListenerHandlers(e),(s||n)&&(t={default:s,fn:t,origin:n}),this._events=this._events||{},this._events[e]=this._addHandler(this._events[e],t)}_buildFacade(e){if(this.getShouldUseFacade()){const t={preventDefault(){t.preventedDefault=!0},target:this,type:e};return t}}disposeInternal(){this._events=null}emit(e){const t=this._getRawListeners(e);if(0===t.length)return!1;const s=Array.prototype.slice.call(arguments,1);return this._runListeners(t,s,this._buildFacade(e)),!0}_getRawListeners(e){return a(this._events&&this._events[e]).concat(a(this._events&&this._events["*"]))}getShouldUseFacade(){return this._shouldUseFacade}listeners(e){return this._getRawListeners(e).map((e=>e.fn?e.fn:e))}many(e,t,s){const n=this._toEventsArray(e);for(let e=0;e<n.length;e++)this._many(n[e],t,s);return new r.default(this,e,s)}_many(e,t,s){const n=this;t<=0||n._addSingleListener(e,(function r(){0==--t&&n.removeListener(e,r),s.apply(n,arguments)}),!1,s)}_matchesListener(e,t){return(e.fn||e)===t||e.origin&&e.origin===t}off(e,t){if(this._validateListener(t),!this._events)return this;const s=this._toEventsArray(e);for(let e=0;e<s.length;e++)this._events[s[e]]=this._removeMatchingListenerObjs(a(this._events[s[e]]),t);return this}on(){return this.addListener.apply(this,arguments)}onListener(e){this._listenerHandlers=this._addHandler(this._listenerHandlers,e)}once(e,t){return this.many(e,1,t)}removeAllListeners(e){if(this._events)if(e){const t=this._toEventsArray(e);for(let e=0;e<t.length;e++)this._events[t[e]]=null}else this._events=null;return this}_removeMatchingListenerObjs(e,t){const s=[];for(let n=0;n<e.length;n++)this._matchesListener(e[n],t)||s.push(e[n]);return s.length>0?s:null}removeListener(){return this.off.apply(this,arguments)}_runListenerHandlers(e){let t=this._listenerHandlers;if(t){t=a(t);for(let s=0;s<t.length;s++)t[s](e)}}_runListeners(e,t,s){s&&t.push(s);const n=[];for(let s=0;s<e.length;s++){const r=e[s].fn||e[s];e[s].default?n.push(r):r.apply(this,t)}if(!s||!s.preventedDefault)for(let e=0;e<n.length;e++)n[e].apply(this,t)}setShouldUseFacade(e){return this._shouldUseFacade=e,this}_toEventsArray(t){return"string"==typeof t&&(e[0]=t,t=e),t}_validateListener(e){if("function"!=typeof e)throw new TypeError("Listener must be a function")}}function a(e){return e=e||[],Array.isArray(e)?e:[e]}var l=h;t.default=l}}));
//# sourceMappingURL=EventEmitter.js.map