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