var __extends=this&&this.__extends||function(){var n=function(t,e){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i])})(t,e)};return function(t,e){function i(){this.constructor=t}n(t,e),t.prototype=null===e?Object.create(e):(i.prototype=e.prototype,new i)}}();import Disposable from"../Disposable.js";import{VOID}from"../functions.js";import Event from"./Event.js";import{clear}from"../obj.js";var Target=function(i){function t(t){var e=i.call(this)||this;return e.target_=t,e.pendingRemovals_={},e.dispatching_={},e.listeners_={},e}return __extends(t,i),t.prototype.addEventListener=function(t,e){var i;t&&e&&(-1===(i=(i=this.listeners_[t])||(this.listeners_[t]=[])).indexOf(e)&&i.push(e))},t.prototype.dispatchEvent=function(t){var e,i="string"==typeof t?new Event(t):t,n=i.type,s=(i.target||(i.target=this.target_||this),this.listeners_[n]);if(s){n in this.dispatching_||(this.dispatching_[n]=0,this.pendingRemovals_[n]=0),++this.dispatching_[n];for(var r=0,o=s.length;r<o;++r)if(!1===s[r].call(this,i)||i.propagationStopped){e=!1;break}if(--this.dispatching_[n],0===this.dispatching_[n]){var p=this.pendingRemovals_[n];for(delete this.pendingRemovals_[n];p--;)this.removeEventListener(n,VOID);delete this.dispatching_[n]}return e}},t.prototype.disposeInternal=function(){clear(this.listeners_)},t.prototype.getListeners=function(t){return this.listeners_[t]},t.prototype.hasListener=function(t){return t?t in this.listeners_:0<Object.keys(this.listeners_).length},t.prototype.removeEventListener=function(t,e){var i=this.listeners_[t];i&&-1!==(e=i.indexOf(e))&&(t in this.pendingRemovals_?(i[e]=VOID,++this.pendingRemovals_[t]):(i.splice(e,1),0===i.length&&delete this.listeners_[t]))},t}(Disposable);export default Target;