/*!
 * @author electricessence / https://github.com/electricessence/
 * Licensing: MIT https://github.com/electricessence/TypeScript.NET/blob/master/LICENSE.md
 */
var __extends=this&&this.__extends||function(e,t){function i(){this.constructor=e}for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r]);e.prototype=null===t?Object.create(t):(i.prototype=t.prototype,new i)};!function(e){if("object"==typeof module&&"object"==typeof module.exports){var t=e(require,exports);void 0!==t&&(module.exports=t)}else"function"==typeof define&&define.amd&&define(["require","exports","../Utility/shallowCopy","../Disposable/DisposableBase","../Collections/Array/Utility","./EventDispatcherEntry","../Disposable/Utility"],e)}(function(e,t){"use strict";function i(){var e=this.params;e.dispatcher.removeEntry(this),e.dispatcher=null}var r=e("../Utility/shallowCopy"),n=e("../Disposable/DisposableBase"),s=e("../Collections/Array/Utility"),o=e("./EventDispatcherEntry"),p=e("../Disposable/Utility"),a="disposing",c="disposed",u=function(e){function t(){e.apply(this,arguments),this._isDisposing=!1}return __extends(t,e),t.prototype.addEventListener=function(e,t,r){void 0===r&&(r=0);var n=this._entries;n||(this._entries=n=[]),n.push(new o["default"](e,t,{priority:r||0,dispatcher:this},i))},t.prototype.removeEntry=function(e){return!!this._entries&&0!=s.remove(this._entries,e)},t.prototype.registerEventListener=function(e,t,i){void 0===i&&(i=0),this.hasEventListener(e,t)||this.addEventListener(e,t,i)},t.prototype.hasEventListener=function(e,t){var i=this._entries;return i&&i.some(function(i){return e==i.type&&(!t||t==i.listener)})},t.prototype.removeEventListener=function(e,t){p.disposeThese(this._entries.filter(function(i){return i.matches(e,t)}))},t.prototype.dispatchEvent=function(e,t){var i=this,n=this,s=n._entries;if(!s||!s.length)return!1;var o;"string"==typeof e?(o=Object.create(Event),t||(t={}),o.cancelable=!!t.cancelable,o.target=n,o.type=e):o=e;var p=o.type,a=s.filter(function(e){return e.type==p});return a.length?(a.sort(function(e,t){return t.params.priority-e.params.priority}),a.forEach(function(e){var t=Object.create(Event);r["default"](o,t),t.target=i,e.dispatch(t)}),!0):!1},Object.defineProperty(t,"DISPOSING",{get:function(){return a},enumerable:!0,configurable:!0}),Object.defineProperty(t,"DISPOSED",{get:function(){return c},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isDisposing",{get:function(){return this._isDisposing},enumerable:!0,configurable:!0}),t.prototype.dispose=function(){var t=this;if(!t.wasDisposed&&!t._isDisposing){t._isDisposing=!0,t.dispatchEvent(a),e.prototype.dispose.call(this),t.dispatchEvent(c);var i=t._entries;i&&(this._entries=null,i.forEach(function(e){return e.dispose()}))}},t}(n["default"]);Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=u});
//# sourceMappingURL=EventDispatcherBase.js.map
