-
Notifications
You must be signed in to change notification settings - Fork 1
/
davy.min.js
2 lines (2 loc) · 3.78 KB
/
davy.min.js
1
2
!function(e){"use strict";function t(e){if(this.value=void 0,this.__deferreds__=[],arguments.length>0){if(!o(e))throw new TypeError("Promise constructor's argument is not a function");n.resolve(this,e)}}function r(e,t,r){return{fulfill:t,reject:r,promise:e}}function n(e){this.promise=e}function i(e){return e&&"object"==typeof e}function o(e){return e&&"function"==typeof e}function u(e){return 0===Object.keys(e).length}function f(e){return i(e)&&o(e.then)}function c(e){if(1===e.length&&Array.isArray(e[0]))return e[0];for(var t=new Array(e.length),r=0;r<t.length;)t[r]=e[r++];return t}var l;"function"==typeof define&&define.amd?define(["subsequent"],function(e){return l=e,t}):"object"==typeof module&&module.exports?(module.exports=t,l=require("subsequent")):(e.Davy=t,l=e.subsequent),t.prototype.isFulfilled=!1,t.prototype.isRejected=!1,t.prototype.then=function(e,i){var o=new t,u=new r(o,e,i);return this.isFulfilled||this.isRejected?n.handle(this,u):this.__deferreds__.push(u),o},n.prototype.fulfill=function(e){n.fulfill(this.promise,e)},n.prototype.reject=function(e){n.reject(this.promise,e)},n.SUCCESS="fulfill",n.FAILURE="reject",n.fulfill=function(e,t){if(!e.isFulfilled&&!e.isRejected){if(t===e)return void n.reject(e,new TypeError("Can't resolve a promise with itself."));if(i(t)||o(t)){var r;try{r=t.then}catch(t){return void n.reject(e,t)}if(o(r))return void n.resolve(e,r.bind(t))}e.isFulfilled=!0,n.complete(e,t)}},n.reject=function(e,t){e.isFulfilled||e.isRejected||(e.isRejected=!0,n.complete(e,t))},n.complete=function(e,t){e.value=t;var r=e.__deferreds__;if(r.length){for(var i=0;i<r.length;)n.handle(e,r[i++]);e.__deferreds__=void 0}},n.handle=function(e,t){var r=e.isFulfilled?n.SUCCESS:n.FAILURE,i=t[r],u=e.value;e=t.promise,l(function(){if(o(i)){var t;try{t=i(u)}catch(t){return void n.reject(e,t)}n.fulfill(e,t)}else n[r](e,u)})},n.resolve=function(e,t){var r=!0;try{t(function(t){r&&(r=!1,n.fulfill(e,t))},function(t){r&&(r=!1,n.reject(e,t))})}catch(t){r&&n.reject(e,t)}},t.prototype.progress=function(e){return this.then(null,null,e)},t.prototype.catch=function(e){return this.then(null,e)},t.prototype.throw=function(){return this.catch(function(e){l(function(){throw e})})},t.prototype.finally=function(e){return this.then(e,e)},t.prototype.yield=function(e){return this.then(function(){return e})},t.prototype.tap=function(e){return this.then(e).yield(this)},t.prototype.spread=function(e,t){return this.then(function(t){return e.apply(this,t)},t)},t.resolve=t.cast=function(e){return f(e)?e:new t(e)},t.reject=function(e){var r=t.defer();return r.reject(e),r.promise},t.defer=function(){return new n(new t)},t.each=function(e,r){var n=t.defer(),i=e.length;0===i&&n.fulfill(TypeError());for(var o=0;o<i;)r(e[o],o++,e);return n},t.all=function(){function e(e){o.reject(e)}function r(t,n,u){return f(t)?void t.then(function(e){r(e,n,u)},e):(u[n]=t,void(0===--i&&o.fulfill(u)))}var n=c(arguments),i=n.length,o=t.each(n,r);return o.promise},t.race=function(){function e(e){i.reject(e)}function r(t){return f(t)?void t.then(r,e):void i.fulfill(t)}var n=c(arguments),i=t.each(n,r);return i.promise},t.wrap=function(e){function r(e,t){e?n.reject(e):n.fulfill(t)}var n=t.defer();return function(){for(var t=arguments.length,i=new Array(t),o=0;o<t;)i[o]=arguments[o++];try{switch(t){case 2:e.call(this,i[0],i[1],r);break;case 1:e.call(this,i[0],r);break;case 0:e.call(this,r);break;default:i.push(r),e.apply(this,i)}}catch(e){n.reject(e)}return n.promise}},t.traverse=function(e,r){function n(e,o){return t.resolve(e).then(function(e){if(!i(e)||u(e))return e;var f=Array.isArray(e),c=f?[]:{},l=Object.keys(e).map(function(i){if(r&&r[o]!==i)return t.resolve();var u=e[i];return f&&(i=c.length),c[i]=null,n(u,o+1).then(function(e){c[i]=e})});return t.all(l).yield(c)})}return n(e,0)}}(Function("return this")());
//# sourceMappingURL=davy.min.js.map