-
Notifications
You must be signed in to change notification settings - Fork 29
/
deferred.min.js
1 lines (1 loc) · 3.22 KB
/
deferred.min.js
1
(function(){var n,e,r,t,o,i,u,l,c,f,s,p,a,h,y=[].slice;o="3.1.0",e="pending",t="resolved",r="rejected",f=function(n,e){return null!=n?n.hasOwnProperty(e):void 0},p=function(n){return f(n,"length")&&f(n,"callee")},a=function(n){return f(n,"promise")&&"function"==typeof(null!=n?n.promise:void 0)},c=function(n){return p(n)?c(Array.prototype.slice.call(n)):Array.isArray(n)?n.reduce(function(n,e){return Array.isArray(e)?n.concat(c(e)):(n.push(e),n)},[]):[n]},u=function(n,e){return n<=0?e():function(){if(--n<1)return e.apply(this,arguments)}},h=function(n,e){return function(){var r;return r=[n].concat(Array.prototype.slice.call(arguments,0)),e.apply(this,r)}},l=function(n,e,r){var t,o,i,u,l;for(u=c(n),l=[],o=0,i=u.length;o<i;o++)t=u[o],l.push(t.call.apply(t,[r].concat(y.call(e))));return l},n=function(){var o,i,u,f,s,p,h;return h=e,f=[],s=[],p=[],u={resolved:{},rejected:{},pending:{}},this.promise=function(o){var i,d;return o=o||{},o.state=function(){return h},d=function(n,r,t){return function(){return h===e&&r.push.apply(r,c(arguments)),n()&&l(arguments,u[t]),o}},o.done=d(function(){return h===t},f,t),o.fail=d(function(){return h===r},s,r),o.progress=d(function(){return h!==e},p,e),o.always=function(){var n;return(n=o.done.apply(o,arguments)).fail.apply(n,arguments)},i=function(e,r,t){var i,u;return u=new n,i=function(n,e,r){return r?o[n](function(){var n,t;return n=1<=arguments.length?y.call(arguments,0):[],t=r.apply(null,n),a(t)?t.done(u.resolve).fail(u.reject).progress(u.notify):u[e](t)}):o[n](u[e])},i("done","resolve",e),i("fail","reject",r),i("progress","notify",t),u},o.pipe=i,o.then=i,null==o.promise&&(o.promise=function(){return o}),o},this.promise(this),o=this,i=function(n,r,t){return function(){return h===e?(h=n,u[n]=arguments,l(r,u[n],t),o):this}},this.resolve=i(t,f),this.reject=i(r,s),this.notify=i(e,p),this.resolveWith=function(n,e){return i(t,f,n).apply(null,e)},this.rejectWith=function(n,e){return i(r,s,n).apply(null,e)},this.notifyWith=function(n,r){return i(e,p,n).apply(null,r)},this},i=function(){var e,r,t,o,i,l,c;if(r=Array.prototype.slice.apply(arguments),1===r.length)return a(r[0])?r[0]:(new n).resolve(r[0]).promise();if(c=new n,!r.length)return c.resolve().promise();for(l=[],t=u(r.length,function(){return c.resolve.apply(c,l)}),r.forEach(function(n,e){return a(n)?n.done(function(){var n;return n=1<=arguments.length?y.call(arguments,0):[],l[e]=n.length>1?n:n[0],t()}):(l[e]=n,t())}),o=0,i=r.length;o<i;o++)e=r[o],a(e)&&e.fail(c.reject);return c.promise()},s=function(e){return e.Deferred=function(){return new n},e.ajax=h(e.ajax,function(e,r){var t,o,i,u;return null==r&&(r={}),o=new n,t=function(n,e){return h(n,function(){var n,r;return r=arguments[0],n=2<=arguments.length?y.call(arguments,1):[],r&&r.apply(null,n),e.apply(null,n)})},r.success=t(r.success,o.resolve),r.error=t(r.error,o.reject),u=e(r),i=o.promise(),i.abort=function(){return u.abort()},i}),e.when=i},"undefined"!=typeof exports?(exports.Deferred=function(){return new n},exports.when=i,exports.installInto=s):"function"==typeof define&&define.amd?define(function(){return"undefined"!=typeof Zepto?s(Zepto):(n.when=i,n.installInto=s,n)}):"undefined"!=typeof Zepto?s(Zepto):(this.Deferred=function(){return new n},this.Deferred.when=i,this.Deferred.installInto=s)}).call(this);