chronosjs
Version:
JS Channels Mechanism
2 lines • 41.2 kB
JavaScript
!function(a,b){"use strict";if("function"==typeof define&&define.amd)define("Chronos.EventsUtil",[],function(){return b(a,a,!0)});else if("object"==typeof exports)b(a,exports);else{a.Chronos=a.Chronos||{};b(a,a.Chronos)}}("undefined"==typeof ChronosRoot?this:ChronosRoot,function(a,b,c){"use strict";function d(a,b,c){var d=[];if(a[b]&&a[b].length)for(var e=0;e<a[b].length;e++)c&&"*"!==a[b][e].appName&&a[b][e].appName!==c||d.push(a[b][e]);if(a["*"])for(var f=0;f<a["*"].length;f++)c&&"*"!==a["*"][f].appName&&a["*"][f].appName!==c||d.push(a["*"][f]);return d}function e(b,c,d){a&&"function"==typeof a.log&&a.log(b,c,d)}function f(a){var b,c=a.unbindObj[a.attrName],d=!1;if(!a.unbindObj){e("CMD listen id not spec for unbind","ERROR",a.loggerName);return null}if("string"==typeof a.unbindObj)return j(a.lstnrs,a.unbindObj);if(!a.unbindObj.func&&!a.unbindObj.context&&!a.unbindObj.appName)return!1;var f=a.lstnrs;if(c){f={};f[c]=a.lstnrs[c]}for(var g in f)if(f.hasOwnProperty(g)&&f[g]&&f[g].length){b=k(f[g],a.unbindObj.func,a.unbindObj.context,a.unbindObj.appName);if(b.length!==f[g].length){a.lstnrs[g]=b;d=!0}}return d}function g(a){var b={};if(a.constructor===Object)for(var c in a)a.hasOwnProperty(c)&&null!==a[c]&&void 0!==a[c]&&("object"==typeof a[c]&&a[c].constructor!==Array?b[c]=g(a[c]):a[c].constructor===Array?b[c]=a[c].slice(0)||[]:"function"!=typeof a[c]&&(b[c]=null!==a[c]&&void 0!==a[c]?a[c]:""));else a.constructor===Array?b=a.slice(0)||[]:"function"!=typeof a&&(b=a);return b}function h(a,b,c){if((void 0===c||"*"===c)&&"*"===b)return a;for(var d=[],e=0;e<a.length;e++)a[e].eventName!==c&&"*"!==c||(b&&b===a[e].appName||!a[e].appName||"*"===a[e].appName||"*"===b)&&d.push(a[e]);return d}function i(a){if(0===a.eventBufferLimit||a.triggerData.data&&a.triggerData.data.doNotStore)a=null;else{var b={eventName:a.triggerData[a.attrName],appName:a.triggerData.appName};b.data=a.triggerData.passDataByRef?a.triggerData.data:g(a.triggerData.data);if(a.eventBufferLimit>0){a.index>=a.eventBufferLimit&&(a.index=0);a.fired[a.index]=b;a.index++}else a.fired.push(b);a=null}}function j(a,b){var c=!1;if(!b){e("Ev listen id not spec for unregister","ERROR","Events");return null}for(var d in a)if(a.hasOwnProperty(d))for(var f=0;f<a[d].length;f++)if(a[d][f].id==b){a[d].splice(f,1);e("Ev listen="+b+" and name="+d+" unregister","DEBUG","Events");c=!0;break}c||e("Ev listen not found "+b+" unregister","DEBUG","Events");return c}function k(a,b,c,d){var f=[];if(a&&a.length)for(var g=0;g<a.length;g++)try{var h=!c&&a[g].func===b,i=!b&&c&&a[g].context===c,j=b&&c&&a[g].func===b&&a[g].context===c,k=d&&d===a[g].appName,l="*"===a[g].appName;if(h||i||j){if(k||l)continue;if(i)continue}else if(!b&&!c&&k)continue;f.push(a[g])}catch(a){e("Error in unbind e="+a.message,"ERROR","Events")}return f}var l={getListeners:d,log:e,unbind:f,hasFired:h,cloneEventData:g,storeEventData:i};c||(b.EventsUtil=b.EventsUtil||l);return l});!function(a,b){"use strict";if("function"==typeof define&&define.amd)define("Chronos.Events",["Chronos.EventsUtil"],function(c){return b(a,a,c,!0)});else if("object"==typeof exports)b(a,exports,require("./util/EventsUtil").EventsUtil);else{a.Chronos=a.Chronos||{};b(a,a.Chronos,a.Chronos.EventsUtil)}}("undefined"==typeof ChronosRoot?this:ChronosRoot,function(a,b,c,d){"use strict";function e(a){function b(a){if(a){a.triggerOnce=!0;return d(a)}return null}function d(a,b,e){var f=a;"string"==typeof a&&(f={appName:a,eventName:b,func:e});f.appName=f.appName||l;"*"!==l&&("string"!=typeof a||"function"!=typeof b&&void 0!==b||(f.eventName=a));if(!f.eventName||!f.func||"function"!=typeof f.func&&f.func.constructor!==Array){c.log("Ev listen has invalid params: evName=["+f.eventName+"]","ERROR","Events");return null}if(f.func.constructor===Array){for(var g,h,i=[],j=0;j<f.func.length;j++){g=c.cloneEventData(f);g.func=f.func[j];h=d(g);i.push(h)}return i}var k=r+o++,m={id:k,func:f.func,context:f.context||null,aSync:!!f.aSync,appName:f.appName,triggerOnce:f.triggerOnce||!1};p[f.eventName]=p[f.eventName]||[];p[f.eventName].push(m);c.log("Ev listen rgstr: evName=["+f.eventName+"] aSync="+m.aSync+" appName="+m.name,"DEBUG","Events");f=null;a=null;return k}function e(a){"*"!==l&&(a.appName=a.appName||l);return c.unbind({unbindObj:a,attrName:n,loggerName:m,lstnrs:p})}function f(a,b){if(void 0===b){b=a;a=l}return c.hasFired(q,a,b)}function g(a,b,d){var e=a;"string"==typeof a&&(e={eventName:b,appName:a,data:d});if("*"!==l){e.appName=e.appName||l;"string"!=typeof a||"object"!=typeof b&&void 0!==b||(e.eventName=a)}if(!e||void 0===e.eventName){c.log("Ev name not spec for publish","ERROR","Events");e=null;return null}e.passDataByRef=e.passDataByRef||!j;i(e);var f=c.getListeners(p,e.eventName,e.appName);if(f.length>0)for(var g=0;g<f.length;g++){var k=e.passDataByRef?e.data:c.cloneEventData(e.data),m={appName:e.appName,eventName:e.eventName},n=f[g];n.aSync||k&&k.aSync?setTimeout(h(n,k,m),0):h(n,k,m)()}e=null;return f.length>0}function h(a,b,d){return function(){try{a.func.call(a.context,b,d);b=null;a.triggerOnce&&e(a);a=null}catch(b){c.log("Error executing "+d.eventName+" eventId: "+a.id+"e="+b.message,"ERROR","Events")}}}function i(a){c.storeEventData({triggerData:a,eventBufferLimit:k,attrName:n,fired:q,index:s})}var j,k,l,m="Events",n="eventName",o=0,p={},q=[],r="evId_",s=0;l=a&&a.appName||"*";j=!(!a||"boolean"!=typeof a.cloneEventData)&&a.cloneEventData;k=a&&!isNaN(a.eventBufferLimit)?a.eventBufferLimit:-1;this.once=b;this.hasFired=f;this.trigger=g;this.publish=g;this.bind=d;this.register=d;this.unbind=e;this.unregister=e}d||(b.Events=b.Events||e);return e});!function(a,b){"use strict";if("function"==typeof define&&define.amd)define("Chronos.CommandsUtil",["Chronos.EventsUtil"],function(c){return b(a,a,c,!0)});else if("object"==typeof exports)b(a,exports,require("./EventsUtil").EventsUtil);else{a.Chronos=a.Chronos||{};b(a,a.Chronos,a.Chronos.EventsUtil)}}("undefined"==typeof ChronosRoot?this:ChronosRoot,function(a,b,c,d){"use strict";function e(a){var b=a.cmd[a.attrName];if(!b||!a.cmd.func||"function"!=typeof a.cmd.func||!f(a.cmd,b)){c.log("comply: has invalid params: command=["+b+"]","ERROR",a.loggerName);return null}if(a.lstnrs[b]&&a.lstnrs[b].length){c.log("comply: cannot comply because command already exist command="+b,"ERROR",a.loggerName);return null}var d=a.prefix+a.id++,e={id:d,func:a.cmd.func,context:a.cmd.context||null,appName:a.cmd.appName};a.lstnrs[b]=a.lstnrs[b]||[];a.lstnrs[b].push(e);c.log("Cmd comply: evName=["+b+"] appName="+e.appName,"DEBUG",a.loggerName);return d}function f(a,b){return!(b&&"*"===b||a.appName&&"*"===a.appName)}var g={bind:e,valid:f};d||(b.CommandsUtil=b.CommandsUtil||g);return g});!function(a,b){"use strict";if("function"==typeof define&&define.amd)define("Chronos.Commands",["Chronos.EventsUtil","Chronos.CommandsUtil"],function(c,d){return b(a,a,c,d,!0)});else if("object"==typeof exports)b(a,exports,require("./util/EventsUtil").EventsUtil,require("./util/CommandsUtil").CommandsUtil);else{a.Chronos=a.Chronos||{};b(a,a.Chronos,a.Chronos.EventsUtil,a.Chronos.CommandsUtil)}}("undefined"==typeof ChronosRoot?this:ChronosRoot,function(a,b,c,d,e){"use strict";function f(a){function b(a){"*"!==k&&(a.appName=a.appName||k);return d.bind({cmd:a,attrName:m,loggerName:l,prefix:q,id:n,lstnrs:o})}function e(a){"*"!==k&&(a.appName=a.appName||k);return c.unbind({unbindObj:a,attrName:m,loggerName:l,lstnrs:o})}function f(a,b){if(void 0===b){b=a;a=k}return c.hasFired(p,a,b)}function g(a,b){if(!a||void 0===a.cmdName||!d.valid(a,a.cmdName)){c.log("CMD name not spec for command","ERROR","Commands");return null}"*"!==k&&(a.appName=a.appName||k);a.passDataByRef=a.passDataByRef||!i;h(a);if(!o[a.cmdName])return!1;var e=c.getListeners(o,a.cmdName,a.appName);if(e.length>0)for(var f=0;f<e.length;f++){var g=a.passDataByRef?a.data:c.cloneEventData(a.data),j=e[f];try{"function"==typeof b?j.func.call(j.context,g,b):j.func.call(j.context,g);g=null;j=null}catch(d){if("function"==typeof b)try{b(d)}catch(b){c.log("Error executing callback on error, "+a.cmdName+" commandId: "+j.id+"e="+b.message,"ERROR","Commands")}c.log("Error executing "+a.cmdName+" commandId: "+j.id+"e="+d.message,"ERROR","Commands")}}return e.length>0}function h(a){c.storeEventData({triggerData:a,eventBufferLimit:j,attrName:m,fired:p,index:r})}var i,j,k,l="Commands",m="cmdName",n=0,o={},p=[],q="cmdId_",r=0;k=a&&a.appName||"*";i=!(!a||"boolean"!=typeof a.cloneEventData)&&a.cloneEventData;j=a&&!isNaN(a.eventBufferLimit)?a.eventBufferLimit:-1;this.hasFired=f;this.comply=b;this.stopComplying=e;this.command=g}e||(b.Commands=b.Commands||f);return f});!function(a,b){"use strict";if("function"==typeof define&&define.amd)define("Chronos.Reqres",["Chronos.EventsUtil","Chronos.CommandsUtil"],function(c,d){return b(a,a,c,d,!0)});else if("object"==typeof exports)b(a,exports,require("./util/EventsUtil").EventsUtil,require("./util/CommandsUtil").CommandsUtil);else{a.Chronos=a.Chronos||{};b(a,a.Chronos,a.Chronos.EventsUtil,a.Chronos.CommandsUtil)}}("undefined"==typeof ChronosRoot?this:ChronosRoot,function(a,b,c,d,e){function f(a){function b(a){"*"!==k&&(a.appName=a.appName||k);return d.bind({cmd:a,attrName:m,loggerName:l,prefix:q,id:n,lstnrs:o})}function e(a){"*"!==k&&(a.appName=a.appName||k);return c.unbind({unbindObj:a,attrName:m,loggerName:l,lstnrs:o})}function f(a,b){if(void 0===b){b=a;a=k}return c.hasFired(p,a,b)}function g(a,b){var e;if(!a||void 0===a.reqName||!d.valid(a,a.reqName)){c.log("request: name not spec for command","ERROR","ReqRes");throw new Error("Invalid request object")}"*"!==k&&(a.appName=a.appName||k);a.passDataByRef=a.passDataByRef||!i;h(a);if(!o[a.reqName])return e;var f=c.getListeners(o,a.reqName,a.appName);if(f.length>0)for(var g=0;g<f.length;g++){var j=a.passDataByRef?a.data:c.cloneEventData(a.data),l={appName:a.appName,reqName:a.reqName},m=f[g];try{e="function"==typeof b?m.func.call(m.context,j,b):m.func.call(m.context,j);j=null;m=null}catch(a){if("function"==typeof b)try{b(a)}catch(a){c.log("Error executing callback on error, "+l.reqName+" requestId: "+m.id+"e="+a.message,"ERROR","ReqRes")}c.log("Error executing "+l.reqName+" requestId: "+m.id+"e="+a.message,"ERROR","ReqRes")}}return e}function h(a){c.storeEventData({triggerData:a,eventBufferLimit:j,attrName:m,fired:p,index:r})}var i,j,k,l="ReqRes",m="reqName",n=0,o={},p=[],q="reqId_",r=0;k=a&&a.appName||"*";i=!(!a||"boolean"!=typeof a.cloneEventData)&&a.cloneEventData;j=a&&!isNaN(a.eventBufferLimit)?a.eventBufferLimit:-1;this.hasFired=f;this.request=g;this.reply=b;this.stopReplying=e}e||(b.ReqRes=b.ReqRes||f);return f});!function(a,b){"use strict";if("function"==typeof define&&define.amd)define("Chronos.Channels",["Chronos.Events","Chronos.Commands","Chronos.Reqres"],function(c,d,e){return b(a,a,c,d,e,!0)});else if("object"==typeof exports)b(a,exports,require("./Events").Events,require("./Commands").Commands,require("./Reqres").ReqRes);else{a.Chronos=a.Chronos||{};b(a,a.Chronos,a.Chronos.Events,a.Chronos.Commands,a.Chronos.ReqRes)}}("undefined"==typeof ChronosRoot?this:ChronosRoot,function(a,b,c,d,e,f){function g(a){function b(a){return function(){var b;a.func.apply(a.context,Array.prototype.slice.call(arguments,0));for(var c=0;c<g.length;c++){b=g[c];if(b[a.triggerType])try{b[a.triggerType].apply(b.context,Array.prototype.slice.call(arguments,0))}catch(a){}}}}function f(a){"object"==typeof a&&a.trigger&&g.push(a)}a=a||{};var g=[],h=a.events||new c(a.config&&a.config.events),i=a.commands||new d(a.config&&a.config.commands),j=a.reqres||new e(a.config&&a.config.reqres);this.once=h.once;this.hasFiredEvents=h.hasFired;this.trigger=h.trigger;this.publish=h.publish;this.bind=h.bind;this.register=h.register;this.unbind=h.unbind;this.unregister=h.unregister;this.hasFiredCommands=i.hasFired;this.comply=i.comply;this.stopComplying=i.stopComplying;this.command=i.command;this.hasFiredReqres=j.hasFired;this.request=j.request;this.reply=j.reply;this.stopReplying=j.stopReplying;if(!0===a.externalProxy){this.trigger=b({func:h.trigger,context:h,triggerType:"trigger"});this.publish=b({func:h.publish,context:h,triggerType:"trigger"});this.registerProxy=f}}f||(b.Channels=b.Channels||g);return g});!function(a,b){"use strict";"function"==typeof define&&define.amd?define("CircuitBreaker",["exports"],function(){a.CircuitBreaker||b(a);return a.CircuitBreaker}):b("object"==typeof exports?exports:a)}("undefined"==typeof CircuitRoot?this:CircuitRoot,function(a){"use strict";function b(a){if(!1==this instanceof b)return new b(a);this.initialize(a)}function c(a){function b(){}function c(){return e.apply(this instanceof b&&a?this:a,d.concat(Array.prototype.slice.call(arguments)))}var d,e;if("function"!=typeof this)throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");d=Array.prototype.slice.call(arguments,1);e=this;b.prototype=this.prototype;c.prototype=new b;return c}var d={OPEN:0,HALF_OPEN:1,CLOSED:2},e={FAILURE:"failure",SUCCESS:"success",TIMEOUT:"timeout",OUTAGE:"outage"};b.prototype=function(){function a(a){if(!this.initialized){a=a||{};this.slidingTimeWindow=!isNaN(a.slidingTimeWindow)&&0<a.slidingTimeWindow?parseInt(a.slidingTimeWindow,10):3e4;this.bucketsNumber=!isNaN(a.bucketsNumber)&&0<a.bucketsNumber?parseInt(a.bucketsNumber,10):10;this.tolerance=!isNaN(a.tolerance)&&0<a.tolerance?parseInt(a.tolerance,10):50;this.calibration=!isNaN(a.calibration)&&0<a.calibration?parseInt(a.calibration,10):5;this.timeout=!isNaN(a.timeout)&&0<a.timeout?parseInt(a.timeout,10):0;this.onopen="function"==typeof a.onopen?a.onopen:function(){};this.onclose="function"==typeof a.onclose?a.onclose:function(){};this.buckets=[l.call(this)];this.state=d.CLOSED;this.initialized=!0;k.call(this)}}function b(a,b,c){if(b&&"function"!=typeof b){c=b;b=void 0}if(h.call(this)){q.call(this,b||function(){});return!1}return p.call(this,a,c)}function c(){this.forced=this.state;this.state=d.OPEN}function f(){this.forced=this.state;this.state=d.CLOSED}function g(){this.state=this.forced;this.forced=void 0}function h(){return d.OPEN===this.state}function i(){for(var a,b,c=0,d=0,f=0;f<this.buckets.length;f++){a=this.buckets[f][e.FAILURE]+this.buckets[f][e.TIMEOUT];d+=a;c+=a+this.buckets[f][e.SUCCESS]}b=d/(c>0?c:1)*100;return{total:c,error:d,percent:b}}function j(){this.timer&&clearTimeout(this.timer);n.call(this);if(this.bucketIndex>this.bucketsNumber){this.bucketIndex=0;h.call(this)&&(this.state=d.HALF_OPEN)}this.timer=setTimeout(j.bind(this),this.bucket)}function k(){this.bucketIndex=0;this.bucket=this.slidingTimeWindow/this.bucketsNumber;this.timer&&clearTimeout(this.timer);this.timer=setTimeout(j.bind(this),this.bucket)}function l(){var a={};a[e.FAILURE]=0;a[e.SUCCESS]=0;a[e.TIMEOUT]=0;a[e.OUTAGE]=0;return a}function m(){return this.buckets[this.buckets.length-1]}function n(){this.bucketIndex++;this.buckets.push(l.call(this));this.buckets.length>this.bucketsNumber&&this.buckets.shift()}function o(a,b){return function(){if(!b.done){if(b.timer){clearTimeout(b.timer);b.timer=null;delete b.timer}m.call(this)[a]++;this.forced||r.call(this);b.done=!0}}.bind(this)}function p(a,b){var c={done:!1},d=o.call(this,e.SUCCESS,c),f=o.call(this,e.FAILURE,c),g=o.call(this,e.TIMEOUT,c);b=!isNaN(b)&&0<b?parseInt(b,10):this.timeout;0<b&&(c.timer=setTimeout(g,b));try{a(d,f,g)}catch(a){f()}}function q(a){try{a()}catch(a){}m.call(this)[e.OUTAGE]++}function r(){var a=i.call(this);if(d.HALF_OPEN===this.state){if(!m.call(this)[e.SUCCESS]&&0<a.error)this.state=d.OPEN;else{this.state=d.CLOSED;this.onclose(a)}}else{var b=a.percent>this.tolerance;if(a.total>this.calibration&&b){this.state=d.OPEN;this.onopen(a)}}}return{initialize:a,run:b,close:f,open:c,reset:g,isOpen:h,calculate:i}}();b.STATE=d;Function.prototype.bind||(Function.prototype.bind=c);a.CircuitBreaker=a.CircuitBreaker||b});!function(a,b){"use strict";"function"==typeof define&&define.amd?define("cacher",["exports"],function(){a.Cacher||b(a);return a.Cacher}):b("object"==typeof exports?exports:a)}("undefined"==typeof CacherRoot?this:CacherRoot,function(a){"use strict";function b(a){if(!1==this instanceof b)return new b(a);this.initialize(a)}b.MAX_STRATEGY={NO_ADD:0,CLOSEST_TTL:1};b.prototype=function(){function a(a){function c(a,b){e.nostore=!0;d.call(e,b.key,b.value,b.ttl);delete e.nostore}var e=this,f=!1,g=0;if(!this.initialized){a=a||{};this.cache={};this.length=0;this.maxStrategy=a.maxStrategy||b.MAX_STRATEGY.NO_ADD;this.max=a.max&&!isNaN(a.max)&&0<a.max?parseInt(a.max,10):0;this.ttl=a.ttl&&!isNaN(a.ttl)&&0<a.ttl?parseInt(a.ttl,10):0;this.interval=a.interval&&!isNaN(a.interval)&&0<a.interval?parseInt(a.interval,10):1e3;this.ontimeout="function"==typeof a.ontimeout?a.ontimeout:function(){};this.onkickout="function"==typeof a.onkickout?a.onkickout:function(){};this.stores=a.stores||[];for(;g<this.stores.length&&!f;){if(this.stores[g].autoload&&this.stores[g].load){f=!0;this.stores[g].load({onitem:c,oncomplete:a.oncomplete})}g++}this.initialized=!0;i.call(this)}}function c(a,b){return b?e.call(this,a):this.cache&&this.cache[a]&&this.cache[a].item}function d(a,b,c,d){return h.call(this,a,b,c,d)}function e(a){var b=this.cache&&this.cache[a]&&this.cache[a].item;if(b){this.cache[a].item=null;this.cache[a].callback=null;this.cache[a].timeout=null;this.cache[a]=null;delete this.cache[a];this.length--;g.call(this,"remove",a)}return b}function f(){if(this.length)for(var a in this.cache)this.cache.hasOwnProperty(a)&&e.call(this,a)}function g(a,b,c,d){if(!this.nostore)for(var e=0;e<this.stores.length;e++)this.stores[e][a]?this.stores[e][a](b,c,d):this.stores[e].save&&this.stores[e].save({items:this.cache})}function h(a,c,d,e){var f,h;if(0===this.max||this.length<this.max||b.MAX_STRATEGY.CLOSEST_TTL===this.maxStrategy){f=d&&!isNaN(d)&&0<d?parseInt(d,10):this.ttl;this.cache[a]={item:c};this.length++;if(f){h=(new Date).getTime()+f;this.cache[a].timeout=h}"function"==typeof e&&(this.cache[a].callback=e);g.call(this,"set",a,c,d);(f&&(this.cache[a].callback||"function"==typeof this.ontimeout||"function"==typeof this.onkickout)||this.max&&this.length>this.max)&&i.call(this,this.max&&this.length>this.max);return!0}return!1}function i(a){var b,c,d,f,g,h=0;this.timer&&clearTimeout(this.timer);if(this.length){for(var j in this.cache)if(this.cache.hasOwnProperty(j)&&this.cache[j].timeout)if(this.cache[j].timeout<=(new Date).getTime()){c=this.cache[j].item;b=this.cache[j].callback;b&&(d=b(j,c));this.ontimeout&&(f=this.ontimeout(j,c));if(!1!==d&&!1!==f){e.call(this,j);h++}else if(!h&&a)if(g){if(g.timeout>this.cache[j].timeout){g.key=j;g.timeout=this.cache[j].timeout}}else g={key:j,timeout:this.cache[j].timeout}}else if(!h&&a)if(g){if(g.timeout>this.cache[j].timeout){g.key=j;g.timeout=this.cache[j].timeout}}else g={key:j,timeout:this.cache[j].timeout};if(!h&&g&&this.cache[g.key]){c=this.cache[g.key].item;b=this.cache[g.key].callback;b&&b(g.key,c);this.onkickout&&this.onkickout(g.key,c);e.call(this,g.key);h++}}this.timer=setTimeout(i.bind(this),this.interval);return h}return{initialize:a,get:c,set:d,remove:e,removeAll:f}}();a.Cacher=a.Cacher||b});!function(a,b,c){"use strict";if("function"==typeof define&&define.amd)define("Chronos.PostMessageUtilities",[],function(){return c(a,b,!0)});else if("object"!=typeof exports){b.Chronos=b.Chronos||{};c(a,b.Chronos)}}(this,"undefined"==typeof ChronosRoot?this:ChronosRoot,function(a,b,c){"use strict";function d(){var a,b;if("function"==typeof Array.prototype.toJSON){b=Array.prototype.toJSON;Array.prototype.toJSON=void 0;try{a=JSON.stringify.apply(null,arguments)}catch(a){Array.prototype.toJSON=b;throw a}Array.prototype.toJSON=b}else a=JSON.stringify.apply(null,arguments);return a}function e(){var b=!0;try{a.postMessage({toString:function(){b=!1}},"*")}catch(a){a&&"DataCloneError"!==a.name&&(b=!1)}return b}function f(a){return a&&a.replace(/[xy]/g,function(a){var b=16*Math.random()|0;return("x"===a?b:3&b|8).toString(16)})}function g(a,b){return!isNaN(a)&&0<a?parseInt(a,10):b}function h(a,b){return"function"==typeof a?a:!0===b?function(){}:b}function i(a,b,c){var d,e,f,g=new RegExp(/(http{1}s{0,1}?:\/\/)([^\/\?]+)(\/?)/gi);if(!a||0!==a.indexOf("http")){f=c?b.top||b.contentWindow&&b.contentWindow.parent||window:b;return f.location.protocol+"//"+f.location.host}d=g.exec(a);d&&3<=d.length&&""!==d[2]&&(e=d[1].toLowerCase()+d[2].toLowerCase());return e}function j(a,b){var c,d=l("lpHost",b);if(!d){c=l("hostParam",b)||a;c&&(d=l(c,b))}return d}function k(a,b,c){var d,e,f;try{e=a&&a.contentWindow&&"undefined"!=typeof Window&&!(a instanceof Window)&&a.getAttribute&&a.getAttribute("src")}catch(a){}try{e||(e=j(c));if(!e){e=document.referrer;f=!0}if(e){e=decodeURIComponent(e);f&&(e=j(c,e))}d=i(e,a,b)}catch(a){q("Cannot parse origin","ERROR","PostMessageUtilities")}return d||"*"}function l(a,b){return decodeURIComponent((new RegExp("[?|&]"+a+"=([^&;]+?)(&|#|;|$)").exec(b||document.location.search)||[void 0,""])[1].replace(/\+/g,"%20"))||null}function m(a,b){var c;"undefined"!=typeof setImmediate&&(isNaN(b)||0>=b)?c=setImmediate(a):!1===b?a():c=setTimeout(a,isNaN(b)||0>=b?0:parseInt(b,10));return function(){n(c)}}function n(a){var b=g(a);b&&("undefined"!=typeof clearImmediate?clearImmediate(b):clearTimeout(b))}function o(a,b,c){a.addEventListener?a.addEventListener(b,c,!1):a.attachEvent("on"+b,c);return function(){p(a,b,c)}}function p(a,b,c){a.removeEventListener?a.removeEventListener(b,c,!1):a.detachEvent("on"+b,c)}function q(b,c,d){a&&"function"==typeof a.log&&a.log(b,c,d)}function r(a){function b(){}function c(){return e.apply(this instanceof b&&a?this:a,d.concat(Array.prototype.slice.call(arguments)))}var d,e;if("function"!=typeof this)throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");d=Array.prototype.slice.call(arguments,1);e=this;b.prototype=this.prototype;c.prototype=new b;return c}Function.prototype.bind||(Function.prototype.bind=r);var s={SEQUENCE_FORMAT:"_xxxxxx-4xxx-yxxx",stringify:d,hasPostMessageObjectsSupport:e,createUniqueSequence:f,parseNumber:g,parseFunction:h,getHost:i,resolveOrigin:k,getURLParameter:l,delay:m,addEventListener:o,removeEventListener:p,log:q,bind:r};c||(b.PostMessageUtilities=b.PostMessageUtilities||s);return s});!function(a,b,c){"use strict";if("function"==typeof define&&define.amd)define("Chronos.PostMessageChannelPolyfill",["Chronos.PostMessageUtilities"],function(d){return c(a,b,d,!0)});else if("object"!=typeof exports){b.Chronos=b.Chronos||{};c(a,b.Chronos,b.Chronos.PostMessageUtilities)}}(this,"undefined"==typeof ChronosRoot?this:ChronosRoot,function(a,b,c,d){"use strict";function e(a,b){if(!1==this instanceof e)return new e(a,b);this.initialize(a,b)}var f="LPPort_";e.prototype=function(){function b(b,d){if(!this.initialized){d=d||{};this.target=b||a.top;this.hosted=this.target===a||this.target===a.top;this.portId=c.createUniqueSequence(f+c.SEQUENCE_FORMAT);this.serialize=c.parseFunction(d.serialize,c.stringify);this.deserialize=c.parseFunction(d.deserialize,JSON.parse);this.initialized=!0}}function d(a){var b,d,e=g.call(this),f=this.target;if(a)try{this.hosted||(f=this.target.contentWindow);b=h.call(this,a);d=this.serialize(b);f.postMessage(d,e)}catch(a){c.log("Error while trying to post the message","ERROR","PostMessageChannelPolyfill");return!1}}function e(a){var b;if("function"==typeof this.onmessage){b=i.call(this,a);return this.onmessage(b)}}function g(){this.origin||(this.origin=c.resolveOrigin(this.target));return this.origin}function h(a){return{port:this.portId,message:a}}function i(a){var b;if(a&&a.data)try{b=this.deserialize(a.data);if(b.port&&0===b.port.indexOf(f))return{origin:a.origin,data:b.message}}catch(a){c.log("Error while trying to deserialize the message","ERROR","PostMessageChannelPolyfill")}return b||a}return{initialize:b,postMessage:d,receive:e}}();d||(b.PostMessageChannelPolyfill=b.PostMessageChannelPolyfill||e);return e});!function(a,b,c){"use strict";if("function"==typeof define&&define.amd)define("Chronos.PostMessageChannel",["Chronos.PostMessageUtilities","Chronos.PostMessageChannelPolyfill"],function(d,e){return c(a,b,d,e,!0)});else if("object"!=typeof exports){b.Chronos=b.Chronos||{};c(a,b.Chronos,b.Chronos.PostMessageUtilities,b.Chronos.PostMessageChannelPolyfill)}}(this,"undefined"==typeof ChronosRoot?this:ChronosRoot,function(a,b,c,d,e){"use strict";function f(a,b){if(!1==this instanceof f)return new f(a,b);this.initialize(a,b)}var g="LPTKN",h="HNDSK";f.prototype=function(){function b(b,e){var f,g;if(!this.initialized){this.hosted=!1;this.messageQueue=[];b=b||{};g=m.call(this,b,e);if(!x.call(this)){this.receiver=new d(this.target,{serialize:this.serialize,deserialize:this.deserialize});this.receiver.onmessage=g}if(this.hosted||!x.call(this)){f=o(g).bind(this);this.removeListener=c.addEventListener(a,"message",f)}else x.call(this)&&this.channelFactory();!this.target||this.loading||this.ready||l.call(this,g,f);this.initialized=!0}}function e(a,b){var d=c.parseFunction(this[a]);if(d){b||d.call(this);this[a]=void 0;delete this[a]}}function f(a){e.call(this,"rmtimer",a)}function i(a){e.call(this,"rmload",a)}function j(){if(!this.disposed){if(this.removeListener){this.removeListener.call(this);this.removeListener=void 0}if(this.targetUrl&&this.target||this.removeDispose)try{this.targetContainer?this.targetContainer.removeChild(this.target):document.body.removeChild(this.target)}catch(a){c.log("Error while trying to remove the iframe from the container","ERROR","PostMessageChannel")}f.call(this);i.call(this);this.messageQueue.length=0;this.messageQueue=void 0;this.channel=void 0;this.onready=void 0;this.disposed=!0}}function k(a,b,d){var e,f;if(!this.disposed)try{if(a){if(this.ready||d){e=b||this.receiver;f=p.call(this,a);e.postMessage(f);return!0}if(this.maxConcurrency>=this.messageQueue.length){this.messageQueue.push(a);return!0}return!1}}catch(a){c.log("Error while trying to post the message","ERROR","PostMessageChannel");return!1}}function l(b,e){var f;try{f=y.call(this)}catch(a){f=!1}if(!f){this.channel=!1;this.receiver=new d(this.target,{serialize:this.serialize,deserialize:this.deserialize});this.receiver.onmessage=b;if(!this.hosted){e=o(b).bind(this);this.removeListener=c.addEventListener(a,"message",e)}y.call(this)}this.handshakeAttempts--;c.delay(function(){if(!this.disposed&&!this.hosted&&!this.ready){this.rmload=C.call(this,this.target);this.rmtimer=c.delay(y.bind(this,this.handshakeInterval),this.handshakeInterval)}}.bind(this))}function m(b,d){var e;n.call(this,b);e=w(d).bind(this);this.channelFactory=r.call(this,e);if(!b.target||(b.target!==a||b.target===a.top)&&"undefined"!=typeof Window&&b.target instanceof Window){this.hosted=!0;this.target=b.target||a.top}else if(b.target.contentWindow)this.target=b.target;else if(b.target.url){this.targetUrl=b.target.url;this.targetOrigin=this.targetOrigin||c.getHost(b.target.url)}this.hosted||(this.token=c.createUniqueSequence(g+c.SEQUENCE_FORMAT));if(this.targetUrl){this.loading=!0;this.targetContainer=b.target.container||document.body;this.target=B.call(this,b.target,this.targetContainer)}return e}function n(a){this.serialize=c.parseFunction(a.serialize,c.stringify);this.deserialize=c.parseFunction(a.deserialize,JSON.parse);this.targetOrigin=a.targetOrigin;this.maxConcurrency=c.parseNumber(a.maxConcurrency,100);this.handshakeInterval=c.parseNumber(a.handshakeInterval,5e3);this.handshakeAttemptsOrig=c.parseNumber(a.handshakeAttempts,3);this.handshakeAttempts=this.handshakeAttemptsOrig;this.hostParam=a.hostParam;this.channel=void 0!==a.channel?a.channel:q();this.useObjects=a.useObjects;this.onready=v(a.onready,a.target).bind(this);this.removeDispose=a.removeDispose}function o(a){return function(b){var d,e;if(b.ports&&0<b.ports.length){this.receiver=b.ports[0];u.call(this,b)&&(this.token||(this.token=b.data));this.receiver.start();e=this.removeListener.bind(this);this.removeListener=c.addEventListener(this.receiver,"message",a);e();this.disposed||!this.hosted||this.ready||(d=!0)}else if(u.call(this,b)){this.token||(this.token=b.data);this.disposed||!this.hosted||this.ready||(d=!0)}else this.token&&this.receiver.receive.call(this.receiver,b);if(d){this.receiver.postMessage(h+this.token);z.call(this)}}}function p(a){s.call(this,a);return this.serialize(a)}function q(){if("true"===c.getURLParameter("lpPMCPolyfill"))return!1}function r(a){return function(){this.channel=new MessageChannel;this.receiver=this.channel.port1;this.dispatcher=this.channel.port2;this.receiver.onmessage=a;this.neutered=!1}.bind(this)}function s(a){this.token&&(a.token=this.token)}function t(a){return a&&a.token===this.token}function u(a){return a&&a.data&&"string"==typeof a.data&&(0===a.data.indexOf(g)||h+this.token===a.data)}function v(a,b){return function(c){b&&"function"==typeof b.callback&&b.callback.call(b.context,c,this.target);a&&("function"==typeof a?a(c,this.target):"function"==typeof a.callback&&a.callback.call(a.context,c,this.target))}}function w(a){return function(b){var d;if(!b.origin||"*"===b.origin||this.targetOrigin===b.origin){if(!u.call(this,b)||this.disposed||this.hosted||this.ready){try{d=this.deserialize(b.data);if(t.call(this,d))return a&&a(d)}catch(a){d=b.data||b;c.log("Error while trying to handle the message","ERROR","PostMessageChannel")}return d||b}z.call(this)}}}function x(){return!1!==this.channel&&"undefined"!=typeof MessageChannel&&"undefined"!=typeof MessagePort}function y(a){f.call(this,!0);if(!this.disposed&&!this.ready){x.call(this)||(this.targetOrigin=this.targetOrigin||c.resolveOrigin(this.target)||"*");if(!this.hosted)if(x.call(this))try{this.neutered&&this.channelFactory();this.target.contentWindow.postMessage(this.token,this.targetOrigin,[this.dispatcher]);this.neutered=!0}catch(a){return!1}else this.target.contentWindow.postMessage(this.token,this.targetOrigin)}if(!this.disposed&&!this.ready&&a)if(0<this.handshakeAttempts){this.handshakeAttempts--;this.rmtimer=c.delay(y.bind(this,a),a)}else this.onready(new Error("Loading: Operation Timeout!"));return!0}function z(){if(!this.disposed&&!this.ready){this.ready=!0;this.handshakeAttempts=this.handshakeAttemptsOrig;this.messageQueue&&this.messageQueue.length?c.delay(function(){var a,b;if(!this.disposed&&this.ready){for(;this.messageQueue&&this.messageQueue.length;){a=this.messageQueue.shift();try{b=p.call(this,a);this.receiver.postMessage(b)}catch(a){c.log("Error while trying to post the message from queue","ERROR","PostMessageChannel")}}this.onready()}}.bind(this)):this.onready()}}function A(b){function d(){f.body?e():c.delay(d,g||100)}b=b||{};var e=b.onready,f=b.doc||a.document,g=b.delay;c.delay(d,g||!1)}function B(a,b){var d=document.createElement("IFRAME"),e=c.createUniqueSequence("LPFRM"+c.SEQUENCE_FORMAT),f=a.delayLoad,g={id:e,name:e,tabindex:"-1","aria-hidden":"true",title:"",role:"presentation",allowTransparency:"true"},h={width:"0px",height:"0px",position:"absolute",top:"-1000px",left:"-1000px"};a.attributes=a.attributes||g;for(var i in a.attributes)a.attributes.hasOwnProperty(i)&&d.setAttribute(i,a.attributes[i]);a.style=a.style||h;if(a.style)for(var j in a.style)a.style.hasOwnProperty(j)&&(d.style[j]=a.style[j]);A({delay:f,onready:function(){(b||document.body).appendChild(d);this.rmload=C.call(this,d);E.call(this,d,a.url,!1!==a.bust)}.bind(this)});return d}function C(a){var b=function(){this.loading=!1;this.handshakeAttempts===this.handshakeAttemptsOrig&&(this.ready=!1);y.call(this,this.handshakeInterval)}.bind(this);c.addEventListener(a,"load",b);return function(){D(a,b)}}function D(a,b){c.removeEventListener(a,"load",b)}function E(a,b,d){b+=0<b.indexOf("?")?"&":"?";if(d){b+="bust=";b+=(new Date).getTime()+"&"}b+=(this.hostParam?"hostParam="+this.hostParam+"&"+this.hostParam+"=":"lpHost=")+encodeURIComponent(c.getHost(void 0,a,!0));x.call(this)||(b+="&lpPMCPolyfill=true");!1===this.useObjects&&(b+="&lpPMDeSerialize=true");a.setAttribute("src",b)}return{initialize:b,postMessage:k,dispose:j}}();e||(b.PostMessageChannel=f);return f});!function(a,b,c){"use strict"
;if("function"==typeof define&&define.amd)define("Chronos.PostMessagePromise",["exports"],function(){return c(a,b,!0)});else if("object"!=typeof exports){b.Chronos=b.Chronos||{};c(a,b.Chronos)}}(this,"undefined"==typeof ChronosRoot?this:ChronosRoot,function(a,b,c){"use strict";function d(a){if(!1==this instanceof d)return new d(a);this.initialize(a)}var e={RESOLVE:"resolve",REJECT:"reject",PROGRESS:"progress"};d.prototype=function(){function a(a){if(!this.initialized){this.queue=[];this.actions={resolve:c.bind(this),reject:d.bind(this),progress:f.bind(this)};"function"==typeof a&&a.call(this,this.actions.resolve,this.actions.reject);this.initialized=!0}}function b(a,b,c){this.queue.push({resolve:a,reject:b,progress:c})}function c(a){h.call(this,e.RESOLVE,a)}function d(a){h.call(this,e.REJECT,a)}function f(a){g.call(this,e.PROGRESS,a)}function g(a,b,c){var d,e;if(this.queue&&this.queue.length){d=0;e=this.queue[d++];for(;e;){e[a]&&e[a].call(this,b);e=this.queue[d++]}c&&(this.queue.length=0)}}function h(a,b){var c=this.actions[a];this.then=function(a,d){c&&c.call(this,b)}.bind(this);this.resolve=this.reject=function(){throw new Error("This Promise instance had already been completed.")};this.progress=function(){return!1};g.call(this,a,b,!0);if(this.queue){this.queue.length=0;delete this.queue}}return{initialize:a,then:b,resolve:c,reject:d,progress:f}}();d.polyfill=function(){a.Promise||(a.Promise=d)};c||(b.PostMessagePromise=b.PostMessagePromise||d);return d});!function(a,b){"use strict";if("function"==typeof define&&define.amd)define("Chronos.PostMessageMapper",["Chronos.PostMessageUtilities"],function(c){return b(a,a,c,!0)});else if("object"!=typeof exports){a.Chronos=a.Chronos||{};b(a,a.Chronos,a.Chronos.PostMessageUtilities)}}("undefined"==typeof ChronosRoot?this:ChronosRoot,function(a,b,c,d){"use strict";function e(a){if(!1==this instanceof e)return new e(a);this.initialize(a)}e.prototype=function(){function a(a){if(!this.initialized){this.eventChannel=a;this.initialized=!0}}function b(a){if(a){if(a.error){c.log("Error on message: "+a.error,"ERROR","PostMessageMapper");return function(){return a}}return e.call(this,a)}}function d(a,b){return{method:{id:a,name:b,args:Array.prototype.slice.call(arguments,2)}}}function e(a){var b=a&&a.method,d=b&&b.name,e=b&&b.args,f=this.eventChannel;return function(){if(f&&f[d])return f[d].apply(f,e);c.log("No channel exists","ERROR","PostMessageMapper")}}return{initialize:a,toEvent:b,toMessage:d}}();d||(b.PostMessageMapper=b.PostMessageMapper||e);return e});!function(a,b,c,d){"use strict";if("function"==typeof define&&define.amd)define("Chronos.PostMessageCourier",["Chronos.PostMessageUtilities","Chronos.Channels","cacher","CircuitBreaker","Chronos.PostMessageChannel","Chronos.PostMessagePromise","Chronos.PostMessageMapper"],function(b,c,e,f,g,h,i){return d(a,a,b,c,e,f,g,h,i,!0)});else if("object"!=typeof exports){a.Chronos=a.Chronos||{};d(a,a.Chronos,a.Chronos.PostMessageUtilities,a.Chronos.Channels,b.Cacher,c.CircuitBreaker,a.Chronos.PostMessageChannel,a.Chronos.PostMessagePromise,a.Chronos.PostMessageMapper)}}("undefined"==typeof ChronosRoot?this:ChronosRoot,"undefined"==typeof CacherRoot?this:CacherRoot,"undefined"==typeof CircuitRoot?this:CircuitRoot,function(a,b,c,d,e,f,g,h,i,j){"use strict";function k(a){if(!1==this instanceof k)return new k(a);this.initialize(a)}var l={TRIGGER:"trigger",COMMAND:"command",REQUEST:"request",RETURN:"return"};k.prototype=function(){function a(a){if(!this.initialized){a=a||{};q.call(this,a);r.call(this,a);s.call(this,a);t.call(this,a);b.call(this,this.eventChannel);this.once=this.eventChannel.once;this.hasFiredEvents=this.eventChannel.hasFiredEvents;this.bind=this.eventChannel.bind;this.register=this.eventChannel.register;this.unbind=this.eventChannel.unbind;this.unregister=this.eventChannel.unregister;this.hasFiredCommands=this.eventChannel.hasFiredCommands;this.comply=this.eventChannel.comply;this.stopComplying=this.eventChannel.stopComplying;this.hasFiredReqres=this.eventChannel.hasFiredReqres;this.reply=this.eventChannel.reply;this.stopReplying=this.eventChannel.stopReplying;this.initialized=!0}}function b(a){a&&"function"==typeof a.registerProxy&&a.registerProxy({trigger:function(){w.call(this,Array.prototype.slice.apply(arguments),l.TRIGGER)},context:this})}function j(){return this.messageChannel}function k(){return this.eventChannel}function m(){if(!this.disposed){var a=Array.prototype.slice.apply(arguments);(2!==arguments.length&&4!==arguments.length||!0!==arguments[arguments.length-1])&&this.eventChannel.trigger.apply(this.eventChannel,a);return w.call(this,a,l.TRIGGER)}}function n(){if(!this.disposed){var a=Array.prototype.slice.apply(arguments);return w.call(this,a,l.COMMAND)}}function o(){if(!this.disposed){var a=Array.prototype.slice.apply(arguments);return w.call(this,a,l.REQUEST)}}function p(){if(!this.disposed){this.messageChannel.dispose();this.messageChannel=void 0;this.eventChannel=void 0;this.mapper=void 0;this.callbackCache=void 0;this.circuit=void 0;this.disposed=!0}}function q(a){this.useObjects=!1===a.useObjects?a.useObjects:u();void 0===this.useObjects&&(this.useObjects=!0);a.useObjects=this.useObjects;if("function"!=typeof a.serialize||"function"!=typeof a.deserialize){if(this.useObjects&&c.hasPostMessageObjectsSupport()){this.serialize=v;this.deserialize=v}else{this.serialize=c.stringify;this.deserialize=JSON.parse}a.serialize=this.serialize;a.deserialize=this.deserialize}else{this.serialize=a.serialize;this.deserialize=a.deserialize}}function r(a){var b,c;this.eventChannel=a.eventChannel||new d({events:a.events,commands:a.commands,reqres:a.reqres});this.mapper=new i(this.eventChannel);b=this.mapper.toEvent.bind(this.mapper);c=E(b).bind(this);this.messageChannel=new g(a,c)}function s(a){this.callbackCache=new e({max:c.parseNumber(a.maxConcurrency,100),ttl:c.parseNumber(a.timeout,3e4),interval:1e3})}function t(a){var b=c.parseNumber(a.messureTime,3e4);this.circuit=new f({timeWindow:b,slidesNumber:Math.ceil(b/100),tolerance:c.parseNumber(a.messureTolerance,30),calibration:c.parseNumber(a.messureCalibration,10),onopen:c.parseFunction(a.ondisconnect,!0),onclose:c.parseFunction(a.onreconnect,!0)})}function u(){if("true"===c.getURLParameter("lpPMDeSerialize"))return!1}function v(a){return a}function w(a,b){return this.circuit.run(function(c,d,e){var f=y.call(this,a,b,e);if(f)try{!1===this.messageChannel.postMessage.call(this.messageChannel,f)?d():c()}catch(a){d()}else d()}.bind(this))}function x(a,b){return this.circuit.run(function(c,d){try{!1===this.messageChannel.postMessage.call(this.messageChannel,a,b)?d():c()}catch(a){d()}}.bind(this))}function y(a,b,d){var e,f,g=c.createUniqueSequence("LPMSG_"+b+c.SEQUENCE_FORMAT);a.unshift(g,b);if(z(b)){if(1<a.length&&"function"==typeof a[a.length-1])e=a.pop();else if(2<a.length&&!isNaN(a[a.length-1])&&"function"==typeof a[a.length-2]){f=parseInt(a.pop(),10);e=a.pop()}if(e&&!this.callbackCache.set(g,e,f,function(a,b){d();A.call(this,a,b)}.bind(this)))return}return this.mapper.toMessage.apply(this.mapper,a)}function z(a){return l.REQUEST===a||l.COMMAND===a}function A(a,b){if(a&&"function"==typeof b)try{b.call(null,new Error("Callback: Operation Timeout!"))}catch(a){c.log("Error while trying to handle the timeout using the callback","ERROR","PostMessageCourier")}}function B(a,b){var d=this.callbackCache.get(a,!0),e=b&&b.args;if("function"==typeof d){e&&e.length&&e[0]&&"Error"===e[0].type&&"string"==typeof e[0].message&&(e[0]=new Error(e[0].message));try{d.apply(null,e)}catch(a){c.log("Error while trying to handle the returned message from request/command","ERROR","PostMessageCourier")}}}function C(a,b,c){return function(d,e){var f,g,h=d;d instanceof Error&&(h={type:"Error",message:d.message});g=[a,l.RETURN,h];l.REQUEST===b&&g.push(e);f=this.mapper.toMessage.apply(this.mapper,g);x.call(this,f,c.source)}.bind(this)}function D(a,b,c,d){var e,f;if("undefined"!=typeof Promise&&c instanceof Promise||c instanceof h)c.then(function(c){f=[a,l.RETURN,null];l.REQUEST===b&&f.push(c);e=this.mapper.toMessage.apply(this.mapper,f);x.call(this,e,d.source)}.bind(this),function(b){f=[a,l.RETURN,b];e=this.mapper.toMessage.apply(this.mapper,f);x.call(this,e,d.source)}.bind(this));else if(c&&c.error){f=[a,l.RETURN,c];e=this.mapper.toMessage.apply(this.mapper,f);x.call(this,e,d.source)}else if(void 0!==c){f=[a,l.RETURN,null];l.REQUEST===b&&f.push(c);e=this.mapper.toMessage.apply(this.mapper,f);x.call(this,e,d.source)}}function E(a){return function(b){var d,e,f,g,h,i,j;if(b){h=b.method&&b.method.id;i=b.method&&b.method.name;j=b.method&&b.method.args;if(l.RETURN===i)B.call(this,h,b.method);else{try{z(i)&&j.length&&j.push(C.call(this,h,i,b));d=a(b);e=d&&d()}catch(a){c.log("Error while trying to invoke the handler on the events channel","ERROR","PostMessageCourier");if(z(i)){f=[h,l.RETURN,{error:a.toString()}];g=this.mapper.toMessage.apply(this.mapper,f);x.call(this,g,b.source)}}z(i)&&void 0!==e&&D.call(this,h,i,e,b)}}}}return{initialize:a,getMessageChannel:j,getEventChannel:k,trigger:m,publish:m,command:n,request:o,dispose:p}}();j||(b.PostMessageCourier=b.PostMessageCourier||k);return k});