usync
Version:
A lightweight library used for serial task control
9 lines • 6.29 kB
JavaScript
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("Usync",[],e):"object"==typeof exports?exports.Usync=e():t.Usync=e()}(this,function(){return function(t){function e(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,e),o.l=!0,o.exports}var r={};return e.m=t,e.c=r,e.d=function(t,r,n){e.o(t,r)||Object.defineProperty(t,r,{configurable:!1,enumerable:!0,get:n})},e.n=function(t){var r=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(r,"a",r),r},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=2)}([function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n,o=r(3),i=r(1);!function(t){t[t.READY=0]="READY",t[t.PENDING=1]="PENDING",t[t.FULFILLED=2]="FULFILLED",t[t.REJECTED=3]="REJECTED"}(n||(n={}));var f=function(){function t(t,e){this.vessel={},this.lifecycleMap=i.init(),this.root=Array.isArray(t)?t:"string"==typeof t?this.setName(t)&&{}:"object"==typeof t?[t]:{},e=o.assign({},e),e.name&&this.setName(e.name),this.root.$name=this.__name__,this.defferd=[],this.index=-1,this.state=n.READY,this.runHook(i.LIFECYCLE[i.LIFECYCLE.init],this)}return t.prototype.fulfilledBroadcast=function(){},Object.defineProperty(t.prototype,"currentDefferd",{get:function(){return this.defferd[this.index]},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"prevDefferd",{get:function(){return this.defferd[this.index-1]},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"nextDefferd",{get:function(){return this.defferd[this.index+1]},enumerable:!0,configurable:!0}),t.prototype.setName=function(t){return this.__name__=t,this},Object.defineProperty(t.prototype,"name",{get:function(){return this.__name__},enumerable:!0,configurable:!0}),t.prototype.use=function(t){if(Array.isArray(t)){for(var e=0,r=t;e<r.length;e++){var o=r[e];this.use(o)}return this}return t.$parent=this,this.runHook(i.LIFECYCLE[i.LIFECYCLE.beforeUse],this,t),this.defferd.push(t),1===this.defferd.length?(this.state=n.PENDING,this.index=0):this.defferd[this.defferd.length-2].__state__===n.FULFILLED&&this.then(),this},t.prototype.then=function(){var e=this;this.currentDefferd.startTime=(new Date).getTime();var r=[this.root].concat(this.done.bind(this));try{if(this.setRootProperty(),this.runHook(i.LIFECYCLE[i.LIFECYCLE.taskStart],this.root),"function"==typeof this.currentDefferd){var n=this.currentDefferd.apply(this,r);n instanceof Promise&&n.then(function(){e.done.call(e)}).catch(function(t){throw t})}else this.currentDefferd instanceof t&&(this.currentDefferd.fulfilledBroadcast=this.done.bind(this),this.currentDefferd.start())}catch(t){if(!this.vessel.catch)throw new Error(t);var o=[t].concat([this.root],this.done.bind(this));this.vessel.catch.apply(this,o)}},t.prototype.setRootProperty=function(){this.root.$current=this.currentDefferd,this.root.$prev=this.prevDefferd,this.root.$next=this.nextDefferd},t.prototype.done=function(){if(this.currentDefferd.__state__=n.FULFILLED,this.currentDefferd.endTime=(new Date).getTime(),this.setRootProperty(),this.runHook(i.LIFECYCLE[i.LIFECYCLE.taskEnd],this.root),++this.index===this.defferd.length)return this.state=n.FULFILLED,this.defferd=[],this.index=-1,this.runHook(i.LIFECYCLE[i.LIFECYCLE.appEnd],this.root),void("function"==typeof this.fulfilledBroadcast&&this.fulfilledBroadcast());void 0!==this.currentDefferd&&void 0===this.currentDefferd.__state__&&this.then()},t.prototype.catch=function(t){return this.vessel.catch=t,this},t.prototype.start=function(){this.runHook(i.LIFECYCLE[i.LIFECYCLE.appStart],this.root),this.startTime=(new Date).getTime(),this.then()},t.prototype.runHook=function(t){for(var e=this,r=[],n=1;n<arguments.length;n++)r[n-1]=arguments[n];var o=t+"Quene";this.lifecycleMap[o].forEach(function(t){return t.apply(e,r)}),this.protoLifecycleMap&&this.protoLifecycleMap[o].forEach(function(t){return t.apply(e,r)})},Object.defineProperty(t.prototype,"protoLifecycleMap",{get:function(){return Object.getPrototypeOf(this).lifecycleMap},enumerable:!0,configurable:!0}),t.prototype.extend=function(t){for(var e=0,r=Object.keys(this.lifecycleMap);e<r.length;e++){var n=r[e],o=n.replace("Quene","");t[o]&&this.lifecycleMap[n].push(t[o])}},t.plugin=function(t,e){},t.app=function(e,r){return new t(e,r)},t.extend=function(t){},t}();e.default=f},function(t,e,r){"use strict";function n(t){var e=Number(t);return!isNaN(e)}function o(){for(var t={},e=0,r=Object.keys(i);e<r.length;e++){var o=r[e];n(o)||(t[o+"Quene"]=[])}return t}Object.defineProperty(e,"__esModule",{value:!0});var i;!function(t){t[t.appStart=1]="appStart",t[t.taskStart=2]="taskStart",t[t.taskEnd=3]="taskEnd",t[t.appEnd=4]="appEnd",t[t.beforeUse=5]="beforeUse",t[t.init=6]="init"}(i=e.LIFECYCLE||(e.LIFECYCLE={})),e.init=o},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});/**
* @license
* Copyright toxichl All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://github.com/toxichl/usync/blob/master/LICENSE
*/
var n=r(0);r(4).default(n.default),t.exports=n.default},function(t,e,r){"use strict";function n(t){for(var e=[],r=1;r<arguments.length;r++)e[r-1]=arguments[r];if(null==t)throw new TypeError("Cannot convert undefined or null to object");t=Object(t);for(var n=0;n<e.length;n++){var o=e[n];if(null!=o)for(var i in o)Object.prototype.hasOwnProperty.call(o,i)&&(t[i]=o[i])}return t}Object.defineProperty(e,"__esModule",{value:!0}),e.assign=n},function(t,e,r){"use strict";function n(t){o.default(t),i.default(t)}Object.defineProperty(e,"__esModule",{value:!0});var o=r(5),i=r(6);e.default=n},function(t,e,r){"use strict";function n(t){t.plugin=function(e,r){"function"==typeof e?e(t,r):"object"==typeof e&&e.install&&e.install(t,r)}}Object.defineProperty(e,"__esModule",{value:!0}),e.default=n},function(t,e,r){"use strict";function n(t){t.extend=function(t){o.default.prototype.lifecycleMap||(o.default.prototype.lifecycleMap=i.init()),o.default.prototype.extend.call(o.default.prototype,t)}}Object.defineProperty(e,"__esModule",{value:!0});var o=r(0),i=r(1);e.default=n}])});
//# sourceMappingURL=Usync.min.js.map