forked from kriskowal/q
-
Notifications
You must be signed in to change notification settings - Fork 2
/
q.min.js
18 lines (18 loc) · 8.54 KB
/
q.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
(function(p){"function"===typeof bootstrap?bootstrap("promise",p):"object"===typeof exports?p(void 0,exports):"function"===typeof define?define(p):"undefined"!==typeof ses?ses.ok()&&(ses.makeQ=function(){return p(void 0,{})}):p(void 0,Q={})})(function(p,b){function H(a,c){c.stack&&("object"===typeof a&&null!==a&&a.stack&&-1===a.stack.indexOf(I))&&(a.stack=J(a.stack)+"\n"+I+"\n"+J(c.stack))}function J(a){for(var a=a.split("\n"),c=[],d=0;d<a.length;++d){var e=a[d],b;if(b=/at .+ \((.*):(\d+):\d+\)/.exec(e)){var h=
b[2];b=b[1]===K&&h>=W&&h<=X}else b=!1;!b&&!(-1!==e.indexOf("(module.js:")||-1!==e.indexOf("(node.js:"))&&c.push(e)}return c.join("\n")}function L(){if(Error.captureStackTrace){var a,c,d=Error.prepareStackTrace;Error.prepareStackTrace=function(d,b){a=b[1].getFileName();c=b[1].getLineNumber()};Error().stack;Error.prepareStackTrace=d;K=a;return c}}function M(a,c,d){return function(){"undefined"!==typeof console&&"function"===typeof console.warn&&console.warn(c+" is deprecated, use "+d+" instead.",Error("").stack);
return a.apply(a,arguments)}}function i(){function a(a){c&&(e=q(a),s(c,function(a,c){l(function(){e.promiseDispatch.apply(e,c)})},void 0),d=c=void 0)}var c=[],d=[],e,b=y(i.prototype),h=y(j.prototype);h.promiseDispatch=function(a,b,h){var k=g(arguments);c?(c.push(k),"when"===b&&h[1]&&d.push(h[1])):l(function(){e.promiseDispatch.apply(e,k)})};h.valueOf=function(){return c?h:e.valueOf()};Error.captureStackTrace&&(Error.captureStackTrace(h,i),h.stack=h.stack.substring(h.stack.indexOf("\n")+1));w(h);b.promise=
h;b.resolve=a;b.reject=function(c){a(m(c))};b.notify=function(a){c&&s(d,function(c,d){l(function(){d(a)})},void 0)};return b}function j(a,c,d,b){void 0===c&&(c=function(a){return m(Error("Promise does not support operation: "+a))});var k=y(j.prototype);k.promiseDispatch=function(d,b,e){var f;try{f=a[b]?a[b].apply(k,e):c.call(k,b,e)}catch(i){f=m(i)}d&&d(f)};d&&(k.valueOf=d);b&&(k.exception=b);w(k);return k}function r(a){return t(a)?a.valueOf():a}function t(a){return a&&"function"===typeof a.promiseDispatch}
function z(a){return!t(r(a))}function N(a){a=r(a);return t(a)&&"exception"in a}function m(a){var a=a||Error(),c=j({when:function(c){if(c){var b=Y(A,this);-1!==b&&(B.splice(b,1),A.splice(b,1))}return c?c(a):m(a)}},function(){return m(a)},function(){return this},a);!O&&("undefined"!==typeof window&&!window.Touch&&window.console)&&console.log("Should be empty:",B);O=!0;A.push(c);B.push(a);return c}function q(a){if(t(a))return a;if((a=r(a))&&"function"===typeof a.then){var c=i();a.then(c.resolve,c.reject,
c.notify);return c.promise}return j({when:function(){return a},get:function(c){return a[c]},put:function(c,b){a[c]=b;return a},del:function(c){delete a[c];return a},post:function(c,b){return a[c].apply(a,b)},apply:function(c){return a.apply(void 0,c)},keys:function(){return Z(a)}},void 0,function(){return a})}function f(a,c,d,b){function k(a){try{return c?c(a):a}catch(d){return m(d)}}function h(a){if(d){H(a,j);try{return d(a)}catch(c){return m(c)}}return m(a)}var f=i(),g=!1,j=q(a);l(function(){j.promiseDispatch(function(a){g||
(g=!0,f.resolve(k(a)))},"when",[function(a){g||(g=!0,f.resolve(h(a)))}])});j.promiseDispatch(void 0,"when",[void 0,function(a){f.notify(b?b(a):a)}]);return f.promise}function P(a,c,d){return f(a,function(a){return x(a).then(function(a){return c.apply(void 0,a)},d)},d)}function C(a,c,d){var b=i();l(function(){q(a).promiseDispatch(b.resolve,c,d)});return b.promise}function o(a){return function(c){var d=g(arguments,1);return C(c,a,d)}}function D(a){var c=g(arguments,1);return u(a,c)}function x(a){return f(a,
function(a){var d=a.length;if(0===d)return q(a);var b=i();s(a,function(k,h,g){z(h)?(a[g]=r(h),0===--d&&b.resolve(a)):f(h,function(f){a[g]=f;0===--d&&b.resolve(a)}).fail(b.reject)},void 0);return b.promise})}function R(a,c){return f(a,void 0,c)}function S(a,c){var d=g(arguments,2),b=i();d.push(b.makeNodeResolver());E(a,c,d).fail(b.reject);return b.promise}var W=L(),K,F=function(){},w=Object.freeze||F;"undefined"!==typeof cajaVM&&(w=cajaVM.def);var l;if("undefined"!==typeof process)l=process.nextTick;
else if("function"===typeof setImmediate)l=setImmediate;else if("undefined"!==typeof MessageChannel){var T=new MessageChannel,v={},U=v;T.port1.onmessage=function(){v=v.next;var a=v.task;delete v.task;a()};l=function(a){U=U.next={task:a};T.port2.postMessage(0)}}else l=function(a){setTimeout(a,0)};var n;Function.prototype.bind?(n=Function.prototype.bind,n=n.bind(n.call)):n=function(a){return function(){return a.call.apply(a,arguments)}};var g=n(Array.prototype.slice),s=n(Array.prototype.reduce||function(a,
c){var d=0,b=this.length;if(arguments.length===1){do{if(d in this){c=this[d++];break}if(++d>=b)throw new TypeError;}while(1)}for(;d<b;d++)d in this&&(c=a(c,this[d],d));return c}),Y=n(Array.prototype.indexOf||function(a){for(var c=0;c<this.length;c++)if(this[c]===a)return c;return-1}),V=n(Array.prototype.map||function(a,c){var b=this,e=[];s(b,function(f,h,g){e.push(a.call(c,h,g,b))},void 0);return e}),y=Object.create||function(a){function c(){}c.prototype=a;return new c},Z=Object.keys||function(a){var c=
[],b;for(b in a)c.push(b);return c},$=Object.prototype.toString,G;G="undefined"!==typeof ReturnValue?ReturnValue:function(a){this.value=a};var I="From previous event:";b.nextTick=l;b.defer=i;i.prototype.makeNodeResolver=function(){var a=this;return function(c,b){c?a.reject(c):arguments.length>2?a.resolve(g(arguments,1)):a.resolve(b)}};b.promise=function(a){var c=i();D(a,c.resolve,c.reject,c.notify).fail(c.reject);return c.promise};b.makePromise=j;j.prototype.then=function(a,c,b){return f(this,a,c,
b)};j.prototype.thenResolve=function(a){return f(this,function(){return a})};s("isResolved isFulfilled isRejected dispatch when spread get put del post send invoke keys fapply fcall fbind all allResolved timeout delay catch finally fail fin progress end done nfcall nfapply nfbind ncall napply nbind npost nsend ninvoke nend nodeify".split(" "),function(a,c){j.prototype[c]=function(){return b[c].apply(b,[this].concat(g(arguments)))}},void 0);j.prototype.toSource=function(){return this.toString()};j.prototype.toString=
function(){return"[object Promise]"};w(j.prototype);b.nearer=r;b.isPromise=t;b.isResolved=function(a){return z(a)||N(a)};b.isFulfilled=z;b.isRejected=N;var A=[],B=[],O;b.reject=m;b.resolve=q;b.master=function(a){return j({isDef:function(){}},function(c,b){return C(a,c,b)},function(){return r(a)})};b.when=f;b.spread=P;b.async=function(a){return function(){function c(a,c){var i;try{i=b[a](c)}catch(j){return $(j)==="[object StopIteration]"||j instanceof G?j.value:m(j)}return f(i,e,g)}var b=a.apply(this,
arguments),e=c.bind(c,"send"),g=c.bind(c,"throw");return e()}};b["return"]=function(a){throw new G(a);};b.promised=function(a){return function(){return P([this,x(arguments)],function(c,b){return a.apply(c,b)})}};b.dispatch=C;b.dispatcher=o;b.get=o("get");b.put=o("put");b["delete"]=b.del=o("del");var E=b.post=o("post");b.send=function(a,c){var b=g(arguments,2);return E(a,c,b)};b.invoke=M(b.send,"invoke","send");var u=b.fapply=o("apply");b["try"]=D;b.fcall=D;b.fbind=function(a){var c=g(arguments,1);
return function(){var b=c.concat(g(arguments));return u(a,b)}};b.keys=o("keys");b.all=x;b.allResolved=function(a){return f(a,function(a){return f(x(V(a,function(a){return f(a,F,F)})),function(){return V(a,q)})})};b["catch"]=b.fail=R;b.progress=function(a,c){return f(a,void 0,void 0,c)};b["finally"]=b.fin=function(a,c){return f(a,function(a){return f(c(),function(){return a})},function(a){return f(c(),function(){return m(a)})})};b.done=function(a,c,d,e){c=c||d||e?f(a,c,d,e):a;R(c,function(c){l(function(){H(c,
a);if(b.onerror)b.onerror(c);else throw c;})})};b.timeout=function(a,c){var b=i(),e=setTimeout(function(){b.reject(Error("Timed out after "+c+" ms"))},c);f(a,function(a){clearTimeout(e);b.resolve(a)},function(a){clearTimeout(e);b.reject(a)});return b.promise};b.delay=function(a,c){if(c===void 0){c=a;a=void 0}var b=i();setTimeout(function(){b.resolve(a)},c);return b.promise};b.nfapply=function(a,c){var b=g(c),e=i();b.push(e.makeNodeResolver());u(a,b).fail(e.reject);return e.promise};b.nfcall=function(a){var c=
g(arguments,1),b=i();c.push(b.makeNodeResolver());u(a,c).fail(b.reject);return b.promise};b.nfbind=function(a){var c=g(arguments,1);return function(){var b=c.concat(g(arguments)),e=i();b.push(e.makeNodeResolver());u(a,b).fail(e.reject);return e.promise}};b.npost=function(a,c,b){var b=g(b),e=i();b.push(e.makeNodeResolver());E(a,c,b).fail(e.reject);return e.promise};b.nsend=S;b.ninvoke=M(S,"ninvoke","nsend");b.nodeify=function(a,b){if(b)a.then(function(a){l(function(){b(null,a)})},function(a){l(function(){b(a)})});
else return a};var X=L()});