extend-promise.min.js 5.0 KB

123456
  1. /*!
  2. * extend-promise v0.0.6
  3. * Homepage https://github.com/cnwhy/extend-promise#readme
  4. * License BSD-2-Clause
  5. */
  6. !function e(n,r,t){function o(u,f){if(!r[u]){if(!n[u]){var c="function"==typeof require&&require;if(!f&&c)return c(u,!0);if(i)return i(u,!0);throw new Error("Cannot find module '"+u+"'")}var s=r[u]={exports:{}};n[u][0].call(s.exports,function(e){var r=n[u][1][e];return o(r?r:e)},s,s.exports,e,n,r,t)}return r[u].exports}for(var i="function"==typeof require&&require,u=0;u<t.length;u++)o(t[u]);return o}({1:[function(e,n,r){!function(e,n){if("function"==typeof define&&(define.amd||define.cmd))define([],n);else{if("undefined"==typeof window&&"undefined"==typeof self)throw new Error("加载 "+e+" 模块失败!,请检查您的环境!");var r="undefined"!=typeof window?window:self;r[e]=n(),"function"==typeof r.Promise&&r[e].auto(r.Promise)}}("extendPromise",function(){var n=e("../index");return n.auto=function(e){n.extendClass(e),n.extendPrototype(e)},n})},{"../index":2}],2:[function(e,n,r){n.exports={extendClass:e("./src/extendClass"),extendPrototype:e("./src/extendPrototype")}},{"./src/extendClass":3,"./src/extendPrototype":4}],3:[function(e,n,r){"use strict";function t(e,n,r){function t(e){if(i(r)){for(var n=!1,t=0;t<r.length;t++)if(r[t]==e){n=!0;break}if(!n)return!1}return!y||!f(d[e])}function o(e,n){return u(n)||(n=+n>0?+n:0),function(r){var t,o=d.defer(),f=0,s=function(i){var c=r[i];d.resolve(c).then(function(r){"undefined"!=typeof n?t.push(r):t[i]=r,(0==--f||!e&&n&&t.length>=n)&&o.resolve(t)},function(e){u(n)?o.reject(e):0==--f&&o.resolve(t)}),f++};if(i(r)){t=[],0==r.length&&o.resolve(t);for(var l=0;l<r.length;l++)s(l)}else if(e&&c(r)){var a=0;t={};for(var l in r)s(l),a++;0==a&&o.resolve(t)}else o.reject(new TypeError("参数错误"));return o.promise}}function l(e){for(var n=d.defer(),r=0;r<e.length;r++)!function(){var t=r,o=e[t];d.resolve(o).then(function(e){n.resolve(e)},function(e){n.reject(e)})}();return n.promise}function a(e){return function(n,r){return n?e.reject(n):void e.resolve(r)}}function p(e){var n=this===d?null:this,r=d.defer(),t=s(arguments,1);return t.push(a(r)),e.apply(n,t),r.promise}var d,y;if(n?(y=!0,d=n):d=e,d.Promise||e==n||(d.Promise=e),f(e)&&f(e.prototype.then))d.defer=function(){var n,r,t=new e(function(e,t){n=e,r=t});return{promise:t,resolve:n,reject:r}};else if(f(e.defer))d.defer=function(){return e.defer()};else{if(!f(e.deferred))throw new TypeError("此类不支持扩展!");d.defer=function(){return e.deferred()}}return t("delay")&&(d.delay=function(e,n){var r=d.defer();return setTimeout(function(){r.resolve(n)},e),r.promise}),t("resolve")&&(d.resolve=function(e){var n=d.defer();return n.resolve(e),n.promise}),t("reject")&&(d.reject=function(e){var n=d.defer();return n.reject(e),n.promise}),t("all")&&(d.all=o()),t("allMap")&&(d.allMap=o(!0)),t("some")&&(d.some=function(e,n){return n=+n>=0?+n:0,o(!1,n)(e)}),t("map")&&(d.map=function(e,n,r){function t(){if(c<s.length){var r=s[c],f=d.resolve(n(e[r],r,e)).then(function(e){return t(),e},o.reject);i.push(f),u--,c++}else d.all(i).then(o.resolve,o.reject)}var o=d.defer(),i=[],u=r?+r.concurrency:0;if(0==u||u!=u){for(var f in e)i.push(n(e[f],f,e));return d.all(i).then(o.resolve,o.reject),o.promise}var c=0,s=function(){var n=[];for(var r in e)n.push(r);return n}();do t();while(u>0&&c<s.length);return o.promise}),t("race")&&(d.race=l),t("any")&&(d.any=l),t("nfcall")&&(d.nfcall=p),t("nfapply")&&(d.nfapply=function(e,n){var r=this===d?null:this,t=d.defer();if(!i(n))throw TypeError('"args" is not Array');return n.push(a(t)),e.apply(r,n),t.promise}),d.denodeify=function(e){var n=this===d?null:this;return function(){return p.apply(n,[].concat([e],s(arguments)))}},d}var o=e("./utils"),i=o.isArray,u=o.isEmpty,f=o.isFunction,c=o.isPlainObject,s=o.arg2arr;n.exports=t},{"./utils":5}],4:[function(e,n,r){function t(e){var n=e.prototype;return n.done=function(e,n){this.then(function(n){"function"==typeof e&&setTimeout(function(){e(n)},0)},function(e){"function"==typeof n?setTimeout(function(){n(e)},0):setTimeout(function(){throw e},0)})},n.spread=function(e,n){return this.then(function(n){return e.apply(null,n)},n)},n.fail=n.catch=function(e){return this.then(null,e)},n.catchOf=function(e,n){return n=n||e,this.then(null,function(r){var t=typeof n;if("function"!=t)throw r;if(e===n)return n(r);if(e===r||"function"==typeof e&&r instanceof e)return n(r);throw r})},n.error=function(e){return this.catchOf(Error,e)},n.fin=n.finally=function(e){var n=function(n,r){try{e(n,r)}catch(e){}};return this.then(function(e){return n(e),e},function(e){throw n(null,e),e})},e}n.exports=t},{}],5:[function(e,n,r){"use strict";r.isPlainObject=function(e){return null!==e&&"object"==typeof e&&!e.nodeType&&e!==e.window&&!(e.constructor&&!Object.prototype.hasOwnProperty.call(e.constructor.prototype,"isPrototypeOf"))},r.isArray=function(e){return"[object Array]"==Object.prototype.toString.call(e)},r.isFunction=function(e){return"function"==typeof e},r.isEmpty=function(e){return"undefined"==typeof e||null===e},r.arg2arr=function(e,n,r){return Array.prototype.slice.call(e,n,r)}},{}]},{},[1]);