UNPKG

typescript-dotnet-amd

Version:

A JavaScript-Friendly .NET Based TypeScript Library.

6 lines 2.5 kB
/*! * @author electricessence / https://github.com/electricessence/ * Licensing: MIT https://github.com/electricessence/TypeScript.NET/blob/master/LICENSE.md */ define(["require","exports","../Collections/Array/Utility","../Utility/shallowCopy","../Disposable/DisposableBase","../Disposable/dispose","./EventDispatcherEntry","../../extends"],function(e,t,r,i,n,s,o,a){"use strict";function p(){var e=this,t=e.params,r=t&&t.dispatcher;r&&(r.removeEntry(e),t.dispatcher=null)}Object.defineProperty(t,"__esModule",{value:!0});var c=a["default"],u="disposing",l="disposed",h="EventDispatcherBase",f=function(e){function t(){var t=e.call(this,h)||this;return t._isDisposing=!1,t}return c(t,e),t.prototype.addEventListener=function(e,t,r){void 0===r&&(r=0);var i=this._entries;i||(this._entries=i=[]),i.push(new o.EventDispatcherEntry(e,t,{priority:r||0,dispatcher:this},p))},t.prototype.removeEntry=function(e){return!!this._entries&&0!=r.remove(this._entries,e)},t.prototype.registerEventListener=function(e,t,r){void 0===r&&(r=0),this.hasEventListener(e,t)||this.addEventListener(e,t,r)},t.prototype.hasEventListener=function(e,t){var r=this._entries;return r&&r.some(function(r){return e==r.type&&(!t||t==r.listener)})||!1},t.prototype.removeEventListener=function(e,t){var r=this._entries;r&&s.dispose.these.noCopy(r.filter(function(r){return r.matches(e,t)}))},t.prototype.dispatchEvent=function(e,t){var r=this,n=this,s=n._entries;if(!s||!s.length)return!1;var o;"string"==typeof e?(o=Event&&Object.create(Event)||{},t||(t={}),t.cancellable&&(o.cancellable=!0),o.target=n,o.type=e):o=e;var a=o.type,p=s.filter(function(e){return e.type==a});return!!p.length&&(p.sort(function(e,t){return(t.params?t.params.priority:0)-(e.params?e.params.priority:0)}),p.forEach(function(e){var t=Object.create(Event);i.shallowCopy(o,t),t.target=r,e.dispatch(t)}),!0)},Object.defineProperty(t,"DISPOSING",{get:function(){return u},enumerable:!0,configurable:!0}),Object.defineProperty(t,"DISPOSED",{get:function(){return l},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(u),e.prototype.dispose.call(this),t.dispatchEvent(l);var r=t._entries;r&&(this._entries=null,r.forEach(function(e){return e.dispose()}))}},t}(n.DisposableBase);t["default"]=f}); //# sourceMappingURL=EventDispatcherBase.js.map