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