chunk-TW5GUTQO.js 3.9 KB

123456789101112
  1. /**
  2. @license
  3. MIT License (c) copyright B Cavalier & J Hann
  4. * A lightweight CommonJS Promises/A and when() implementation
  5. * when is part of the cujo.js family of libraries
  6. *
  7. * Licensed under the MIT License at:
  8. *
  9. * @version 1.7.1
  10. */var M,T,S;o.defer=k;o.resolve=y;o.reject=D;o.join=K;o.all=Q;o.map=x;o.reduce=N;o.any=J;o.some=L;o.allSettled=I;o.chain=U;o.isPromise=A;function o(e,n,t,r){return y(e).then(n,t,r)}function y(e){var n,t;return e instanceof P?n=e:A(e)?(t=k(),e.then(function(r){t.resolve(r)},function(r){t.reject(r)},function(r){t.progress(r)}),n=t.promise):n=G(e),n}function D(e){return o(e,b)}function P(e){this.then=e}P.prototype={always:function(e,n){return this.then(e,e,n)},otherwise:function(e){return this.then(S,e)},yield:function(e){return this.then(function(){return e})},spread:function(e){return this.then(function(n){return Q(n,function(t){return e.apply(S,t)})})}};function G(e){var n=new P(function(t){try{return y(t?t(e):e)}catch(r){return b(r)}});return n}function b(e){var n=new P(function(t,r){try{return r?y(r(e)):b(e)}catch(u){return b(u)}});return n}function k(){var e,n,t,r,u,i,g;return n=new P(s),e={then:s,resolve:c,reject:d,progress:l,promise:n,resolver:{resolve:c,reject:d,progress:l}},t=[],r=[],u=function(f,v,a){var h,j;return h=k(),j=typeof a=="function"?function(w){try{h.progress(a(w))}catch(R){h.progress(R)}}:function(w){h.progress(w)},t.push(function(w){w.then(f,v).then(h.resolve,h.reject,j)}),r.push(j),h.promise},i=function(f){return H(r,f),f},g=function(f){return f=y(f),u=f.then,g=y,i=_,H(t,f),r=t=S,f},e;function s(f,v,a){return u(f,v,a)}function c(f){return g(f)}function d(f){return g(b(f))}function l(f){return i(f)}}function A(e){return e&&typeof e.then=="function"}function L(e,n,t,r,u){return E(2,arguments),o(e,function(i){var g,s,c,d,l,f,v,a,h,j;if(h=i.length>>>0,g=Math.max(0,Math.min(n,h)),c=[],s=h-g+1,d=[],l=k(),!g)l.resolve(c);else for(a=l.progress,v=function(m){d.push(m),--s||(f=v=_,l.reject(d))},f=function(m){c.push(m),--g||(f=v=_,l.resolve(c))},j=0;j<h;++j)j in i&&o(i[j],R,w,a);return l.then(t,r,u);function w(m){v(m)}function R(m){f(m)}})}function I(e,n,t,r){return E(1,arguments),o(e,function(u){var i,g,s,c,d,l,f,v,a;for(f=u.length>>>0,v=u.length>>>0,i=[],g=[],s=k(),l=s.progress,d=function(p){g.push(p),--v||(c=d=_,s.resolve(i))},c=function(p,C){i[C]=p,--v||(c=d=_,s.resolve(i))},a=0;a<f;++a)switch(a){case 0:o(u[a],w,h,l);break;case 1:o(u[a],R,h,l);break;case 2:o(u[a],m,h,l);break;case 3:o(u[a],z,h,l);break;case 4:o(u[a],B,h,l);break;default:o(u[a],j,h,l);break}return s.then(n,t,r);function h(p){d(p)}function j(p){c(p,0)}function w(p){c(p,0)}function R(p){c(p,1)}function m(p){c(p,2)}function z(p){c(p,3)}function B(p){c(p,4)}})}function J(e,n,t,r){function u(i){return n?n(i[0]):i[0]}return L(e,1,u,t,r)}function Q(e,n,t,r){return E(1,arguments),x(e,q).then(n,t,r)}function K(){return x(arguments,q)}function x(e,n){return o(e,function(t){var r,u,i,g,s,c;if(i=u=t.length>>>0,r=[],c=k(),!i)c.resolve(r);else for(g=function(l,f){o(l,n).then(function(v){r[f]=v,--i||c.resolve(r)},c.reject)},s=0;s<u;s++)s in t?g(t[s],s):--i;return c.promise})}function N(e,n){var t=T.call(arguments,1);return o(e,function(r){var u;return u=r.length,t[0]=function(i,g,s){return o(i,function(c){return o(g,function(d){return n(c,d,s,u)})})},M.apply(r,t)})}function U(e,n,t){var r=arguments.length>2;return o(e,function(u){return u=r?t:u,n.resolve(u),u},function(u){return n.reject(u),b(u)},n.progress)}function H(e,n){for(var t,r=0;t=e[r++];)t(n)}function E(e,n){for(var t,r=n.length;r>e;)if(t=n[--r],t!=null&&typeof t!="function")throw new Error("arg "+r+" must be a function")}function _(){}T=[].slice;M=[].reduce||function(e){var n,t,r,u,i;if(i=0,n=Object(this),u=n.length>>>0,t=arguments,t.length<=1)for(;;){if(i in n){r=n[i++];break}if(++i>=u)throw new TypeError}else r=t[1];for(;i<u;++i)i in n&&(r=e(r,n[i],i,n));return r};function q(e){return e}var W=o;export{W as a};