forked from kriskowal/q
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathq-0.2.4.min.js
7 lines (7 loc) · 3.13 KB
/
q-0.2.4.min.js
1
2
3
4
5
6
7
(function(d,g){function l(a){return a}function q(){var a=[],b,c=n(h.prototype);c.emit=function(){var e=Array.prototype.slice.call(arguments);a?a.push(e):o.apply(g,[b].concat(e))};c.valueOf=function(){if(a)return c;return b.valueOf()};var f=function(e){var i;if(a){b=m(e);e=0;for(i=a.length;e<i;++e)o.apply(g,[b].concat(a[e]));a=g;return b}};return{promise:r(c),resolve:f,reject:function(e){return f(j(e))}}}function h(a,b,c){if(b===g)b=function(e){return j("Promise does not support operation: "+e)};var f=
n(h.prototype);f.emit=function(e,i){var s=Array.prototype.slice.call(arguments,2);s=a[e]?a[e].apply(a,s):b.apply(a,arguments);i=i||l;return i(s)};if(c)f.valueOf=c;return r(f)}function t(a){return a instanceof h}function v(a){if(a===g||a===null)return true;return!w(a)&&!t(a.valueOf())}function w(a){if(a===g||a===null)return false;return a.valueOf()instanceof j}function j(a){return h({when:function(b){return b?b(a):j(a)}},function(b,c){c=c||l;return c(j(a))},function(){var b=n(j.prototype);b.reason=
a;return b})}function m(a){if(t(a))return a;return h({when:function(){return a},get:function(b){return a[b]},put:function(b,c){a[b]=c},del:function(b){delete a[b]},post:function(b){var c=Array.prototype.slice.call(arguments,1),f=a[b];if(!f)throw Error("No such method "+b+" on object "+a);if(!f.apply)throw Error("Property "+b+" on object "+a+" is not a method");return a[b].apply(a,c)},keys:function(){return Object.keys(a)}},g,function(){return a})}function x(a,b,c){var f=q(),e=false;o(m(a),"when",
function(i){if(!e){e=true;f.resolve(m(i).emit("when",b,c))}},function(i){if(!e){e=true;f.resolve(c?c(i):j(i))}});return f.promise}function k(a){return function(b){var c=Array.prototype.slice.call(arguments,1);return u.apply(g,[b,a].concat(c))}}function u(a,b){var c=q(),f=Array.prototype.slice.call(arguments,2);o.apply(g,[m(a),b,c.resolve].concat(f));return c.promise}function o(a){var b=Array.prototype.slice.call(arguments,1);p(function(){try{a.emit.apply(a,b)}catch(c){y(c.stack||c)}})}var p;try{p=
require("event-queue").enqueue}catch(z){p=function(a){setTimeout(a,0)}}var y;y=typeof console!=="undefined"?function(a){console.log(a)}:typeof require!=="undefined"?require("system").print:function(){};var r=Object.freeze||l,n=Object.create||function(a){var b=function(){};b.prototype=a;return new b};d.enqueue=p;d.defer=q;d.Promise=h;h.prototype.toSource=function(){return this.toString()};h.prototype.toString=function(){return"[object Promise]"};r(h.prototype);d.isPromise=t;d.isResolved=v;d.isRejected=
w;d.reject=j;j.prototype=n(h.prototype,{constructor:{value:j}});d.ref=m;d.def=function(a){return h({isDef:function(){}},function(b,c){var f=Array.prototype.slice.call(arguments,2);f=u.apply(g,[a,b].concat(f));c=c||l;return c(f)},function(){return a.valueOf()})};d.when=x;d.asap=function(a,b,c){b=b||l;return v(a)?b(a.valueOf()).valueOf():x(a,b,c)};d.Method=k;d.send=u;d.get=k("get");d.put=k("put");d.del=k("del");d.post=k("post");d.keys=k("keys");d.defined=function(a){return d.when(a,function(b){if(b===
g||b===null)return j("Resolved undefined value: "+b);return b})};d.error=function(a){a instanceof Error||(a=Error(a));throw a;}})(typeof exports!=="undefined"?exports:this["/q"]={});