lie-ts
Version:
The Smallest & Fastest TS Promise lib.
1 lines • 3.9 kB
JavaScript
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var n=t();for(var o in n)("object"==typeof exports?exports:e)[o]=n[o]}}(this,function(){return function(e){function t(o){if(n[o])return n[o].exports;var r=n[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,t),r.l=!0,r.exports}var n={};return t.m=e,t.c=n,t.i=function(e){return e},t.d=function(e,n,o){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:o})},t.n=function(e){var n=e&&e.e?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=1)}([function(e,t){function n(e,n,o){t.setFast(function(){var t;try{t=n.apply(null,o)}catch(t){return j.t(e,t)}return t===e?j.t(e,new TypeError):j.r(e,t),null})}function o(e){var t=e&&e.then;return!e||"object"!=typeof e&&"function"!=typeof e||"function"!=typeof t?null:function(){t.apply(e,arguments)}}function r(e,t){function n(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];u||(u=!0,j.t(e,t))}function o(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];u||(u=!0,j.r(e,t))}function r(){t(o,n)}var u=!1,c=i(r);"error"===c.u&&n(c.f)}function i(e,t){var n={u:null,f:null};try{n.f=e(t),n.u="success"}catch(e){n.u="error",n.f=e}return n}Object.defineProperty(t,"__esModule",{value:!0});var u=0,c={},f=Array.prototype.slice,l="undefined"!=typeof window&&window.postMessage&&window.addEventListener,s=function(e){return e[0].apply(null,f.call(e,1))},a=function(e){var t,n=e.data;"string"==typeof n&&0===n.indexOf("setMsg")&&(t=c[n])&&(delete c[n],s(t))};l&&window.addEventListener("message",a);var _=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=u++,o="setMsg"+n;return c[o]=e,window.postMessage(o,"*"),n};t.setFast=function(){return l?_:function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];setTimeout(function(){s(e)},0)}}();var p=function(){},h=["R"],d=["F"],v=["P"],y=function(){function e(e){this.a=v,this._=[],this.h=void 0,e!==p&&r(this,e)}return e.doPolyFill=function(){"undefined"!=typeof global&&(global.Promise||(global.Promise=this)),"undefined"!=typeof window&&(window.Promise||(window.Promise=this))},e.prototype.catch=function(e){return this.then(function(){},e)},e.prototype.then=function(t,o){if("function"!=typeof t&&this.a===d||"function"!=typeof o&&this.a===h)return this;var r=new e(p);return this.a!==v?n(r,this.a===d?t:o,this.h):this._.push(new w(r,t,o)),r},e.resolve=function(t){return t instanceof this?t:j.r(new e(p),t)},e.reject=function(t){return j.t(new e(p),t)},e.all=function(t){return new e(function(e,n){var o=[];if(!t.length)return void e([]);for(var r=function(n,r,i){void 0!==i?o.push(i):o.push(r),o.length==t.length&&e(o)},i=0;i<t.length;i++)!function(e){t[e].then(function(e){r(0,e,void 0)}).catch(function(e){r(0,void 0,e)})}(i)})},e.race=function(t){var n=this,o=t.length,r=!1,i=-1,u=new e(p);if(!1!==Array.isArray(t))return this.reject(new TypeError);if(!o)return this.resolve([]);for(;++i<o;)!function(e){n.resolve(e).then(function(e){r||(r=!0,j.r(u,e))},function(e){r||(r=!0,j.t(u,e))})}(t[i]);return u},e}();t.Promise=y;var w=function(){function e(e,t,n){this.v=e,"function"==typeof t&&(this.y=t,this.w=this.j),"function"==typeof n&&(this.g=n,this.b=this.x)}return e.prototype.w=function(e){j.r(this.v,e)},e.prototype.j=function(e){n(this.v,this.y,e)},e.prototype.b=function(e){j.t(this.v,e)},e.prototype.x=function(e){n(this.v,this.g,e)},e}();t.F=w;var j=function(){function e(){}return e.r=function(t,n){var u=i(o,n),c=u.f,f=-1,l=t._.length;if("error"===u.u)return e.t(t,u.f);if(c)r(t,c);else for(t.a=d,t.h=n;++f<l;)t._[f].w(n);return t},e.t=function(e,t){e.a=h,e.h=t;for(var n=-1,o=e._.length;++n<o;)e._[n].b(t);return e},e}()},function(e,t,n){e.exports=n(0)}])});