UNPKG

@jokio/ts-events

Version:

Various EventEmitter event replacements with synchronous, a-synchronous, and queued events. Made in TypeScript so usable with JavaScript and TypeScript.

1 lines 26.1 kB
!function(f){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=f();else if("function"==typeof define&&define.amd)define([],f);else{var g;g="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,g.listComponent=f()}}(function(){return require=function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a="function"==typeof require&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n||e)},l,l.exports,e,t,n,r)}return n[o].exports}for(var i="function"==typeof require&&require,o=0;o<r.length;o++)s(r[o]);return s}({1:[function(require,module,exports){"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var sync_event_1=require("./sync-event"),EventQueue=function(){function EventQueue(){this.evtFilled=new sync_event_1.SyncEvent,this.evtDrained=new sync_event_1.SyncEvent,this._queue=[],this._flushing=!1}return EventQueue.global=function(){return EventQueue._instance||EventQueue.resetGlobal(),EventQueue._instance},EventQueue.resetGlobal=function(){EventQueue._instance=new EventQueue},EventQueue.prototype.empty=function(){return 0===this._queue.length},EventQueue.prototype.add=function(handler){this._queue.push(handler),1!==this._queue.length||this._flushing||this.evtFilled.post(this)},EventQueue.prototype.flushOnce=function(){var empty=0===this._queue.length,flushing=this._flushing;this._flushing=!0;try{var queue=this._queue;this._queue=[];for(var i=0;i<queue.length;++i)queue[i]()}finally{this._flushing=flushing,empty||flushing||0!==this._queue.length||this.evtDrained.post(this)}},EventQueue.prototype.flush=function(maxRounds){void 0===maxRounds&&(maxRounds=10);var empty=0===this._queue.length,flushing=this._flushing;this._flushing=!0;try{for(var i=0;this._queue.length>0;){if("number"==typeof maxRounds&&i>=maxRounds)throw this._queue=[],new Error("unable to flush the queue due to recursively added event. Clearing queue now");this.flushOnce(),++i}}finally{this._flushing=flushing,empty||flushing||0!==this._queue.length||this.evtDrained.post(this)}},EventQueue}();exports.default=EventQueue},{"./sync-event":7}],2:[function(require,module,exports){"use strict";var __extends=this&&this.__extends||function(){var extendStatics=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(d,b){d.__proto__=b}||function(d,b){for(var p in b)b.hasOwnProperty(p)&&(d[p]=b[p])};return function(d,b){function __(){this.constructor=d}extendStatics(d,b),d.prototype=null===b?Object.create(b):(__.prototype=b.prototype,new __)}}(),__awaiter=this&&this.__awaiter||function(thisArg,_arguments,P,generator){return new(P||(P=Promise))(function(resolve,reject){function fulfilled(value){try{step(generator.next(value))}catch(e){reject(e)}}function rejected(value){try{step(generator.throw(value))}catch(e){reject(e)}}function step(result){result.done?resolve(result.value):new P(function(resolve){resolve(result.value)}).then(fulfilled,rejected)}step((generator=generator.apply(thisArg,_arguments||[])).next())})},__generator=this&&this.__generator||function(thisArg,body){function verb(n){return function(v){return step([n,v])}}function step(op){if(f)throw new TypeError("Generator is already executing.");for(;_;)try{if(f=1,y&&(t=y[2&op[0]?"return":op[0]?"throw":"next"])&&!(t=t.call(y,op[1])).done)return t;switch(y=0,t&&(op=[0,t.value]),op[0]){case 0:case 1:t=op;break;case 4:return _.label++,{value:op[1],done:!1};case 5:_.label++,y=op[1],op=[0];continue;case 7:op=_.ops.pop(),_.trys.pop();continue;default:if(t=_.trys,!(t=t.length>0&&t[t.length-1])&&(6===op[0]||2===op[0])){_=0;continue}if(3===op[0]&&(!t||op[1]>t[0]&&op[1]<t[3])){_.label=op[1];break}if(6===op[0]&&_.label<t[1]){_.label=t[1],t=op;break}if(t&&_.label<t[2]){_.label=t[2],_.ops.push(op);break}t[2]&&_.ops.pop(),_.trys.pop();continue}op=body.call(thisArg,_)}catch(e){op=[6,e],y=0}finally{f=t=0}if(5&op[0])throw op[1];return{value:op[0]?op[1]:void 0,done:!0}}var f,y,t,_={label:0,sent:function(){if(1&t[0])throw t[1];return t[1]},trys:[],ops:[]};return{next:verb(0),throw:verb(1),return:verb(2)}};Object.defineProperty(exports,"__esModule",{value:!0});var EventType,objects_1=require("./objects"),sync_event_1=require("./sync-event"),async_event_1=require("./async-event"),queued_event_1=require("./queued-event");!function(EventType){EventType[EventType.Sync=0]="Sync",EventType[EventType.Async=1]="Async",EventType[EventType.Queued=2]="Queued"}(EventType=exports.EventType||(exports.EventType={}));var AnyEvent=function(){function AnyEvent(opts){this._events=[],opts&&opts.monitorAttach&&(this.evtFirstAttached=new VoidAnyEvent,this.evtLastDetached=new VoidAnyEvent)}return AnyEvent.prototype.attach=function(){for(var args=[],_i=0;_i<arguments.length;_i++)args[_i]=arguments[_i];var mode=EventType.Sync;args.length>0&&"number"==typeof args[0]&&(mode=args.shift());var handler,opts,postable,boundTo=this;"function"==typeof args[0]||args[0]&&"object"==typeof args[0]&&"function"==typeof args[0].post?("function"==typeof args[0]?handler=args[0]:postable=args[0],opts=args[1]):(boundTo=args[0],handler=args[1],opts=args[2]),this._attach(mode,boundTo,handler,postable,opts,!1)},AnyEvent.prototype.once=function(){for(var args=[],_i=0;_i<arguments.length;_i++)args[_i]=arguments[_i];var mode=EventType.Sync;args.length>0&&"number"==typeof args[0]&&(mode=args.shift());var handler,opts,postable,boundTo=this;"function"==typeof args[0]||args[0]&&"object"==typeof args[0]&&"function"==typeof args[0].post?("function"==typeof args[0]?handler=args[0]:postable=args[0],opts=args[1]):(boundTo=args[0],handler=args[1],opts=args[2]),this._attach(mode,boundTo,handler,postable,opts,!0)},AnyEvent.prototype._attach=function(mode,boundTo,handler,postable,opts,once){var event,prevCount=this.evtFirstAttached?this.listenerCount():0;switch(mode){case EventType.Sync:for(var _i=0,_a=this._events;_i<_a.length;_i++){var evt=_a[_i];evt instanceof sync_event_1.SyncEvent&&(event=evt)}event||(event=new sync_event_1.SyncEvent,this._events.push(event));break;case EventType.Async:for(var _b=0,_c=this._events;_b<_c.length;_b++){var evt=_c[_b];evt instanceof async_event_1.AsyncEvent&&objects_1.shallowEquals(evt.options,opts)&&(event=evt)}event||(event=new async_event_1.AsyncEvent(opts),this._events.push(event));break;case EventType.Queued:for(var _d=0,_e=this._events;_d<_e.length;_d++){var evt=_e[_d];evt instanceof queued_event_1.QueuedEvent&&objects_1.shallowEquals(evt.options,opts)&&(event=evt)}event||(event=new queued_event_1.QueuedEvent(opts),this._events.push(event));break;default:throw new Error("unknown EventType")}once?postable?event.once(postable):event.once(boundTo,handler):postable?event.attach(postable):event.attach(boundTo,handler),this.evtFirstAttached&&0===prevCount&&this.evtFirstAttached.post()},AnyEvent.prototype.attachSync=function(){for(var args=[],_i=0;_i<arguments.length;_i++)args[_i]=arguments[_i];args.unshift(EventType.Sync),this.attach.apply(this,args)},AnyEvent.prototype.onceSync=function(){for(var args=[],_i=0;_i<arguments.length;_i++)args[_i]=arguments[_i];args.unshift(EventType.Sync),this.once.apply(this,args)},AnyEvent.prototype.attachAsync=function(){for(var args=[],_i=0;_i<arguments.length;_i++)args[_i]=arguments[_i];args.unshift(EventType.Async),this.attach.apply(this,args)},AnyEvent.prototype.onceAsync=function(){for(var args=[],_i=0;_i<arguments.length;_i++)args[_i]=arguments[_i];args.unshift(EventType.Async),this.once.apply(this,args)},AnyEvent.prototype.attachQueued=function(){for(var args=[],_i=0;_i<arguments.length;_i++)args[_i]=arguments[_i];args.unshift(EventType.Queued),this.attach.apply(this,args)},AnyEvent.prototype.onceQueued=function(){for(var args=[],_i=0;_i<arguments.length;_i++)args[_i]=arguments[_i];args.unshift(EventType.Queued),this.once.apply(this,args)},AnyEvent.prototype.detach=function(){for(var args=[],_i=0;_i<arguments.length;_i++)args[_i]=arguments[_i];for(var prevCount=this.evtLastDetached?this.listenerCount():0,i=0;i<this._events.length;++i)this._events[i].detach.apply(this._events[i],args);this.evtLastDetached&&prevCount>0&&0===this.listenerCount()&&this.evtLastDetached.post()},AnyEvent.prototype.post=function(data){return __awaiter(this,void 0,void 0,function(){var events,i,i;return __generator(this,function(_a){switch(_a.label){case 0:for(events=[],i=0;i<this._events.length;++i)events.push(this._events[i]);i=0,_a.label=1;case 1:return i<events.length?[4,events[i].post(data)]:[3,4];case 2:_a.sent(),_a.label=3;case 3:return++i,[3,1];case 4:return[2]}})})},AnyEvent.prototype.listenerCount=function(){for(var result=0,i=0;i<this._events.length;++i)result+=this._events[i].listenerCount();return result},AnyEvent}();exports.AnyEvent=AnyEvent;var VoidAnyEvent=function(_super){function VoidAnyEvent(){return null!==_super&&_super.apply(this,arguments)||this}return __extends(VoidAnyEvent,_super),VoidAnyEvent.prototype.post=function(){return _super.prototype.post.call(this,void 0)},VoidAnyEvent}(AnyEvent);exports.VoidAnyEvent=VoidAnyEvent;var ErrorAnyEvent=function(_super){function ErrorAnyEvent(){return null!==_super&&_super.apply(this,arguments)||this}return __extends(ErrorAnyEvent,_super),ErrorAnyEvent.prototype.post=function(data){if(0===this.listenerCount())throw new Error("error event posted while no listeners attached. Error: "+data.message);return _super.prototype.post.call(this,data)},ErrorAnyEvent}(AnyEvent);exports.ErrorAnyEvent=ErrorAnyEvent},{"./async-event":3,"./objects":5,"./queued-event":6,"./sync-event":7}],3:[function(require,module,exports){"use strict";var __extends=this&&this.__extends||function(){var extendStatics=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(d,b){d.__proto__=b}||function(d,b){for(var p in b)b.hasOwnProperty(p)&&(d[p]=b[p])};return function(d,b){function __(){this.constructor=d}extendStatics(d,b),d.prototype=null===b?Object.create(b):(__.prototype=b.prototype,new __)}}(),__awaiter=this&&this.__awaiter||function(thisArg,_arguments,P,generator){return new(P||(P=Promise))(function(resolve,reject){function fulfilled(value){try{step(generator.next(value))}catch(e){reject(e)}}function rejected(value){try{step(generator.throw(value))}catch(e){reject(e)}}function step(result){result.done?resolve(result.value):new P(function(resolve){resolve(result.value)}).then(fulfilled,rejected)}step((generator=generator.apply(thisArg,_arguments||[])).next())})},__generator=this&&this.__generator||function(thisArg,body){function verb(n){return function(v){return step([n,v])}}function step(op){if(f)throw new TypeError("Generator is already executing.");for(;_;)try{if(f=1,y&&(t=y[2&op[0]?"return":op[0]?"throw":"next"])&&!(t=t.call(y,op[1])).done)return t;switch(y=0,t&&(op=[0,t.value]),op[0]){case 0:case 1:t=op;break;case 4:return _.label++,{value:op[1],done:!1};case 5:_.label++,y=op[1],op=[0];continue;case 7:op=_.ops.pop(),_.trys.pop();continue;default:if(t=_.trys,!(t=t.length>0&&t[t.length-1])&&(6===op[0]||2===op[0])){_=0;continue}if(3===op[0]&&(!t||op[1]>t[0]&&op[1]<t[3])){_.label=op[1];break}if(6===op[0]&&_.label<t[1]){_.label=t[1],t=op;break}if(t&&_.label<t[2]){_.label=t[2],_.ops.push(op);break}t[2]&&_.ops.pop(),_.trys.pop();continue}op=body.call(thisArg,_)}catch(e){op=[6,e],y=0}finally{f=t=0}if(5&op[0])throw op[1];return{value:op[0]?op[1]:void 0,done:!0}}var f,y,t,_={label:0,sent:function(){if(1&t[0])throw t[1];return t[1]},trys:[],ops:[]};return{next:verb(0),throw:verb(1),return:verb(2)}};Object.defineProperty(exports,"__esModule",{value:!0});var base_event_1=require("./base-event"),AsyncEvent=function(_super){function AsyncEvent(opts){var _this=_super.call(this)||this;_this._queued=!1,_this.options=opts;var options=opts||{};return"boolean"==typeof options.condensed?_this._condensed=options.condensed:_this._condensed=!1,_this}return __extends(AsyncEvent,_super),AsyncEvent.defaultScheduler=function(callback){"undefined"!=typeof window?setTimeout(callback,0):setImmediate(callback)},AsyncEvent.setScheduler=function(scheduler){AsyncEvent._scheduler=scheduler},AsyncEvent.prototype.post=function(){for(var _this=this,args=[],_i=0;_i<arguments.length;_i++)args[_i]=arguments[_i];if(this._listeners&&0!==this._listeners.length)if(this._condensed){if(this._queuedData=args,this._queuedListeners=this._listeners,this._queued)return;this._queued=!0,AsyncEvent._scheduler(function(){_this._queued=!1;for(var data=_this._queuedData,listeners=_this._queuedListeners,i=0;i<listeners.length;++i){var listener=listeners[i];_this._call(listener,data)}})}else{var listeners_1=this._listeners;AsyncEvent._scheduler(function(){for(var i=0;i<listeners_1.length;++i){var listener=listeners_1[i];_this._call(listener,args)}})}},AsyncEvent.prototype._call=function(listener,args){return __awaiter(this,void 0,void 0,function(){return __generator(this,function(_a){return listener.event&&listener.event instanceof AsyncEvent?listener.event._postDirect(args):_super.prototype._call.call(this,listener,args),[2]})})},AsyncEvent.prototype._postDirect=function(args){if(this._listeners&&0!==this._listeners.length)for(var listeners=this._listeners,i=0;i<listeners.length;++i){var listener=listeners[i];this._call(listener,args)}},AsyncEvent}(base_event_1.BaseEvent);AsyncEvent._scheduler=AsyncEvent.defaultScheduler,exports.AsyncEvent=AsyncEvent;var VoidAsyncEvent=function(_super){function VoidAsyncEvent(){return null!==_super&&_super.apply(this,arguments)||this}return __extends(VoidAsyncEvent,_super),VoidAsyncEvent.prototype.post=function(){return _super.prototype.post.call(this,void 0)},VoidAsyncEvent}(AsyncEvent);exports.VoidAsyncEvent=VoidAsyncEvent;var ErrorAsyncEvent=function(_super){function ErrorAsyncEvent(){return null!==_super&&_super.apply(this,arguments)||this}return __extends(ErrorAsyncEvent,_super),ErrorAsyncEvent.prototype.post=function(data){if(0===this.listenerCount())throw new Error("error event posted while no listeners attached. Error: "+data.message);return _super.prototype.post.call(this,data)},ErrorAsyncEvent}(AsyncEvent);exports.ErrorAsyncEvent=ErrorAsyncEvent},{"./base-event":4}],4:[function(require,module,exports){"use strict";var __awaiter=this&&this.__awaiter||function(thisArg,_arguments,P,generator){return new(P||(P=Promise))(function(resolve,reject){function fulfilled(value){try{step(generator.next(value))}catch(e){reject(e)}}function rejected(value){try{step(generator.throw(value))}catch(e){reject(e)}}function step(result){result.done?resolve(result.value):new P(function(resolve){resolve(result.value)}).then(fulfilled,rejected)}step((generator=generator.apply(thisArg,_arguments||[])).next())})},__generator=this&&this.__generator||function(thisArg,body){function verb(n){return function(v){return step([n,v])}}function step(op){if(f)throw new TypeError("Generator is already executing.");for(;_;)try{if(f=1,y&&(t=y[2&op[0]?"return":op[0]?"throw":"next"])&&!(t=t.call(y,op[1])).done)return t;switch(y=0,t&&(op=[0,t.value]),op[0]){case 0:case 1:t=op;break;case 4:return _.label++,{value:op[1],done:!1};case 5:_.label++,y=op[1],op=[0];continue;case 7:op=_.ops.pop(),_.trys.pop();continue;default:if(t=_.trys,!(t=t.length>0&&t[t.length-1])&&(6===op[0]||2===op[0])){_=0;continue}if(3===op[0]&&(!t||op[1]>t[0]&&op[1]<t[3])){_.label=op[1];break}if(6===op[0]&&_.label<t[1]){_.label=t[1],t=op;break}if(t&&_.label<t[2]){_.label=t[2],_.ops.push(op);break}t[2]&&_.ops.pop(),_.trys.pop();continue}op=body.call(thisArg,_)}catch(e){op=[6,e],y=0}finally{f=t=0}if(5&op[0])throw op[1];return{value:op[0]?op[1]:void 0,done:!0}}var f,y,t,_={label:0,sent:function(){if(1&t[0])throw t[1];return t[1]},trys:[],ops:[]};return{next:verb(0),throw:verb(1),return:verb(2)}};Object.defineProperty(exports,"__esModule",{value:!0});var BaseEvent=function(){function BaseEvent(){}return BaseEvent.prototype.attach=function(a,b){this._attach(a,b,!1)},BaseEvent.prototype.once=function(a,b){this._attach(a,b,!0)},BaseEvent.prototype._attach=function(a,b,once){return __awaiter(this,void 0,void 0,function(){var boundTo,handler,event;return __generator(this,function(_a){if("function"==typeof a)handler=a;else if(b||"function"!=typeof a.post){if("object"!=typeof a)throw new Error("Expect a function or object as first argument");if("function"!=typeof b)throw new Error("Expect a function as second argument");boundTo=a,handler=b}else event=a;return this._listeners?this._listeners=this._listeners.slice():this._listeners=[],this._listeners.push({deleted:!1,boundTo:boundTo,handler:handler,event:event,once:once}),[2]})})},BaseEvent.prototype.detach=function(){for(var args=[],_i=0;_i<arguments.length;_i++)args[_i]=arguments[_i];if(this._listeners&&0!==this._listeners.length){var boundTo,handler,event;args.length>=1&&("function"==typeof args[0]?handler=args[0]:1===args.length&&"function"==typeof args[0].post?event=args[0]:boundTo=args[0]),args.length>=2&&(handler=args[1]),this._listeners=this._listeners.filter(function(listener){return void 0!==handler&&listener.handler!==handler||void 0!==event&&listener.event!==event||void 0!==boundTo&&listener.boundTo!==boundTo||(listener.deleted=!0,!1)}),0===this._listeners.length&&delete this._listeners}},BaseEvent.prototype.post=function(data){throw new Error("abstract")},BaseEvent.prototype.listenerCount=function(){return this._listeners?this._listeners.length:0},BaseEvent.prototype._call=function(listener,args){return __awaiter(this,void 0,void 0,function(){return __generator(this,function(_a){switch(_a.label){case 0:return listener.deleted?[3,4]:(listener.once&&(listener.deleted=!0,this._listeners=this._listeners.filter(function(l){return l!==listener}),0===this._listeners.length&&delete this._listeners),listener.event?[4,listener.event.post.apply(listener.event,args)]:[3,2]);case 1:return _a.sent(),[3,4];case 2:return[4,listener.handler.apply("object"==typeof listener.boundTo?listener.boundTo:this,args)];case 3:_a.sent(),_a.label=4;case 4:return[2]}})})},BaseEvent}();exports.BaseEvent=BaseEvent},{}],5:[function(require,module,exports){"use strict";function shallowEquals(a,b){if(a===b)return!0;if(typeof a!=typeof b)return!1;switch(typeof a){case"boolean":case"number":case"string":case"function":case"symbol":case"undefined":return!1;case"object":if(null===a||null===b)return!1;if(Array.isArray(a)||Array.isArray(b)){if(!Array.isArray(a)||!Array.isArray(b))return!1;if(a.length!==b.length)return!1;for(var i=0;i<a.length;++i)if(a[i]!==b[i])return!1;return!0}var namesA=[],namesB=[];for(var name_1 in a)a.hasOwnProperty(name_1)&&namesA.push(name_1);for(var name_2 in b)b.hasOwnProperty(name_2)&&namesB.push(name_2);if(namesA.sort(),namesB.sort(),namesA.join(",")!==namesB.join(","))return!1;for(var i=0;i<namesA.length;++i)if(a[namesA[i]]!==b[namesA[i]])return!1;return!0;default:return!1}}Object.defineProperty(exports,"__esModule",{value:!0}),exports.shallowEquals=shallowEquals},{}],6:[function(require,module,exports){"use strict";var __extends=this&&this.__extends||function(){var extendStatics=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(d,b){d.__proto__=b}||function(d,b){for(var p in b)b.hasOwnProperty(p)&&(d[p]=b[p])};return function(d,b){function __(){this.constructor=d}extendStatics(d,b),d.prototype=null===b?Object.create(b):(__.prototype=b.prototype,new __)}}();Object.defineProperty(exports,"__esModule",{value:!0});var base_event_1=require("./base-event"),EventQueue_1=require("./EventQueue"),QueuedEvent=function(_super){function QueuedEvent(opts){var _this=_super.call(this)||this;_this._queued=!1,_this.options=opts;var options=opts||{};return"boolean"==typeof options.condensed?_this._condensed=options.condensed:_this._condensed=!1,"object"==typeof options.queue&&null!==options.queue&&(_this._queue=options.queue),_this}return __extends(QueuedEvent,_super),QueuedEvent.prototype.post=function(){for(var _this=this,args=[],_i=0;_i<arguments.length;_i++)args[_i]=arguments[_i];if(this._listeners&&0!==this._listeners.length){var queue=this._queue?this._queue:EventQueue_1.default.global();if(this._condensed){if(this._queuedData=args,this._queuedListeners=this._listeners,this._queued)return;this._queued=!0,queue.add(function(){_this._queued=!1;for(var data=_this._queuedData,listeners=_this._queuedListeners,i=0;i<listeners.length;++i){var listener=listeners[i];_this._call(listener,data)}})}else{var listeners_1=this._listeners;queue.add(function(){for(var i=0;i<listeners_1.length;++i){var listener=listeners_1[i];_this._call(listener,args)}})}}},QueuedEvent}(base_event_1.BaseEvent);exports.QueuedEvent=QueuedEvent;var VoidQueuedEvent=function(_super){function VoidQueuedEvent(){return null!==_super&&_super.apply(this,arguments)||this}return __extends(VoidQueuedEvent,_super),VoidQueuedEvent.prototype.post=function(){return _super.prototype.post.call(this,void 0)},VoidQueuedEvent}(QueuedEvent);exports.VoidQueuedEvent=VoidQueuedEvent;var ErrorQueuedEvent=function(_super){function ErrorQueuedEvent(){return null!==_super&&_super.apply(this,arguments)||this}return __extends(ErrorQueuedEvent,_super),ErrorQueuedEvent.prototype.post=function(data){if(!this._listeners||0===this._listeners.length)throw new Error("error event posted while no listeners attached. Error: "+data.message);return _super.prototype.post.call(this,data)},ErrorQueuedEvent}(QueuedEvent);exports.ErrorQueuedEvent=ErrorQueuedEvent},{"./EventQueue":1,"./base-event":4}],7:[function(require,module,exports){"use strict";var __extends=this&&this.__extends||function(){var extendStatics=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(d,b){d.__proto__=b}||function(d,b){for(var p in b)b.hasOwnProperty(p)&&(d[p]=b[p])};return function(d,b){function __(){this.constructor=d}extendStatics(d,b),d.prototype=null===b?Object.create(b):(__.prototype=b.prototype,new __)}}(),__awaiter=this&&this.__awaiter||function(thisArg,_arguments,P,generator){return new(P||(P=Promise))(function(resolve,reject){function fulfilled(value){try{step(generator.next(value))}catch(e){reject(e)}}function rejected(value){try{step(generator.throw(value))}catch(e){reject(e)}}function step(result){result.done?resolve(result.value):new P(function(resolve){resolve(result.value)}).then(fulfilled,rejected)}step((generator=generator.apply(thisArg,_arguments||[])).next())})},__generator=this&&this.__generator||function(thisArg,body){function verb(n){return function(v){return step([n,v])}}function step(op){if(f)throw new TypeError("Generator is already executing.");for(;_;)try{if(f=1,y&&(t=y[2&op[0]?"return":op[0]?"throw":"next"])&&!(t=t.call(y,op[1])).done)return t;switch(y=0,t&&(op=[0,t.value]),op[0]){case 0:case 1:t=op;break;case 4:return _.label++,{value:op[1],done:!1};case 5:_.label++,y=op[1],op=[0];continue;case 7:op=_.ops.pop(),_.trys.pop();continue;default:if(t=_.trys,!(t=t.length>0&&t[t.length-1])&&(6===op[0]||2===op[0])){_=0;continue}if(3===op[0]&&(!t||op[1]>t[0]&&op[1]<t[3])){_.label=op[1];break}if(6===op[0]&&_.label<t[1]){_.label=t[1],t=op;break}if(t&&_.label<t[2]){_.label=t[2],_.ops.push(op);break}t[2]&&_.ops.pop(),_.trys.pop();continue}op=body.call(thisArg,_)}catch(e){op=[6,e],y=0}finally{f=t=0}if(5&op[0])throw op[1];return{value:op[0]?op[1]:void 0,done:!0}}var f,y,t,_={label:0,sent:function(){if(1&t[0])throw t[1];return t[1]},trys:[],ops:[]};return{next:verb(0),throw:verb(1),return:verb(2)}};Object.defineProperty(exports,"__esModule",{value:!0});var base_event_1=require("./base-event"),SyncEvent=function(_super){function SyncEvent(){var _this=null!==_super&&_super.apply(this,arguments)||this;return _this._recursion=0,_this}return __extends(SyncEvent,_super),SyncEvent.prototype.post=function(){for(var args=[],_i=0;_i<arguments.length;_i++)args[_i]=arguments[_i];return __awaiter(this,void 0,void 0,function(){var listeners,i,listener;return __generator(this,function(_a){switch(_a.label){case 0:if(!this._listeners||0===this._listeners.length)return[2];if(this._recursion++,SyncEvent.MAX_RECURSION_DEPTH>0&&this._recursion>SyncEvent.MAX_RECURSION_DEPTH)throw new Error("event fired recursively");listeners=this._listeners,i=0,_a.label=1;case 1:return i<listeners.length?(listener=listeners[i],[4,this._call(listener,args)]):[3,4];case 2:_a.sent(),_a.label=3;case 3:return++i,[3,1];case 4:return this._recursion--,[2]}})})},SyncEvent}(base_event_1.BaseEvent);SyncEvent.MAX_RECURSION_DEPTH=10,exports.SyncEvent=SyncEvent;var VoidSyncEvent=function(_super){function VoidSyncEvent(){return null!==_super&&_super.apply(this,arguments)||this}return __extends(VoidSyncEvent,_super),VoidSyncEvent.prototype.post=function(){return _super.prototype.post.call(this,void 0)},VoidSyncEvent}(SyncEvent);exports.VoidSyncEvent=VoidSyncEvent;var ErrorSyncEvent=function(_super){function ErrorSyncEvent(){return null!==_super&&_super.apply(this,arguments)||this}return __extends(ErrorSyncEvent,_super),ErrorSyncEvent.prototype.post=function(data){if(0===this.listenerCount())throw new Error("error event posted while no listeners attached. Error: "+data.message);return _super.prototype.post.call(this,data)},ErrorSyncEvent}(SyncEvent);exports.ErrorSyncEvent=ErrorSyncEvent},{"./base-event":4}],"ts-events":[function(require,module,exports){"use strict";function __export(m){for(var p in m)exports.hasOwnProperty(p)||(exports[p]=m[p])}function queue(){return EventQueue_1.default.global()}function flushOnce(){EventQueue_1.default.global().flushOnce()}function flush(maxRounds){void 0===maxRounds&&(maxRounds=10),EventQueue_1.default.global().flush(maxRounds)}Object.defineProperty(exports,"__esModule",{value:!0}),__export(require("./base-event")),__export(require("./sync-event")),__export(require("./queued-event")),__export(require("./async-event")),__export(require("./any-event"));var EventQueue_1=require("./EventQueue"),EventQueue_2=require("./EventQueue");exports.EventQueue=EventQueue_2.default,exports.queue=queue,exports.flushOnce=flushOnce,exports.flush=flush},{"./EventQueue":1,"./any-event":2,"./async-event":3,"./base-event":4,"./queued-event":6,"./sync-event":7}]},{},[]),require("ts-events")});