-
Notifications
You must be signed in to change notification settings - Fork 45
/
vow.min.js
1 lines (1 loc) · 9.11 KB
/
vow.min.js
1
!function(e){var t=function(){var t=[],n=function(e){return t.push(e),1===t.length},r=function(){var e=t,n=0,r=t.length;for(t=[];n<r;)e[n ]()},i=e.MutationObserver||e.WebKitMutationObserver;if(i){var o=1,s=document.createTextNode("");return new i(r).observe(s,{characterData:!0}),function(e){n(e)&&(s.data=o*=-1)}}if("object"==typeof process&&process.nextTick)return function(e){n(e)&&process.nextTick(r)};if("function"==typeof setImmediate)return function(e){n(e)&&setImmediate(r)};if(e.postMessage){var l=!0;if(e.attachEvent){var u=function(){l=!1};e.attachEvent("onmessage",u),e.postMessage("__checkAsync","*"),e.detachEvent("onmessage",u)}if(l){var c="__promise" Math.random() "_" new Date,a=function(e){e.data===c&&(e.stopPropagation&&e.stopPropagation(),r())};return e.addEventListener?e.addEventListener("message",a,!0):e.attachEvent("onmessage",a),function(t){n(t)&&e.postMessage(c,"*")}}}var f=e.document;if("onreadystatechange"in f.createElement("script")){return function(e){var t;n(e)&&((t=f.createElement("script")).onreadystatechange=function(){t.parentNode.removeChild(t),t=t.onreadystatechange=null,r()},(f.documentElement||f.body).appendChild(t))}}return function(e){n(e)&&setTimeout(r,0)}}(),n=function(e){t(function(){throw e})},r=function(e){return"function"==typeof e},i=function(e){return null!==e&&"object"==typeof e},o=Object.prototype.toString,s=Array.isArray||function(e){return"[object Array]"===o.call(e)},l=function(e){for(var t=[],n=0,r=e.length;n<r;)t.push(n );return t},u=Object.keys||function(e){var t=[];for(var n in e)e.hasOwnProperty(n)&&t.push(n);return t},c=function(e,t){return function(n){e.call(this,n,t)}},a=e.PromiseRejectionEvent?function(t,n){new e.PromiseRejectionEvent("unhandledrejection",{promise:n,reason:t})}:"object"==typeof process&&process.emit?function(e,t){process.emit("unhandledRejection",e,t)}:function(){},f=function(){this._promise=new _};f.prototype={promise:function(){return this._promise},resolve:function(e){this._promise.isResolved()||this._promise._resolve(e)},reject:function(e){this._promise.isResolved()||(b.isPromise(e)?(e=e.then(function(e){var t=b.defer();return t.reject(e),t.promise()}),this._promise._resolve(e)):this._promise._reject(e))},notify:function(e){this._promise.isResolved()||this._promise._notify(e)}};var h=0,d=1,v=2,p=3,_=function(e){if(this._value=void 0,this._status=h,this._shouldEmitUnhandledRejection=!0,this._fulfilledCallbacks=[],this._rejectedCallbacks=[],this._progressCallbacks=[],e){var t=this,n=e.length;try{e(function(e){t.isResolved()||t._resolve(e)},n>1?function(e){t.isResolved()||t._reject(e)}:void 0,n>2?function(e){t.isResolved()||t._notify(e)}:void 0)}catch(e){this._reject(e)}}};_.prototype={valueOf:function(){return this._value},isResolved:function(){return this._status!==h},isFulfilled:function(){return this._status===v},isRejected:function(){return this._status===p},then:function(e,t,n,r){this._shouldEmitUnhandledRejection=!1;var i=new f;return this._addCallbacks(i,e,t,n,r),i.promise()},catch:function(e,t){return this.then(void 0,e,t)},fail:function(e,t){return this.then(void 0,e,t)},always:function(e,t){var n=this,r=function(){return e.call(this,n)};return this.then(r,r,t)},finally:function(e,t){var n=this,r=function(){return e.call(this)};return this.then(r,r,t).then(function(){return n})},progress:function(e,t){return this.then(void 0,void 0,e,t)},spread:function(e,t,n){return this.then(function(t){return e.apply(this,t)},t,n)},done:function(e,t,r,i){this.then(e,t,r,i).fail(n)},delay:function(e){var t,n=this.then(function(n){var r=new f;return t=setTimeout(function(){r.resolve(n)},e),r.promise()});return n.always(function(){clearTimeout(t)}),n},timeout:function(e){var t=new f,n=setTimeout(function(){t.reject(new b.TimedOutError("timed out"))},e);return this.then(function(e){t.resolve(e)},function(e){t.reject(e)}),t.promise().always(function(){clearTimeout(n)}),t.promise()},_vow:!0,_resolve:function(e){if(!(this._status>d))if(e!==this)if(this._status=d,e&&e._vow)e.isFulfilled()?this._fulfill(e.valueOf()):e.isRejected()?(e._shouldEmitUnhandledRejection=!1,this._reject(e.valueOf())):e.then(this._fulfill,this._reject,this._notify,this);else{if(i(e)||r(e)){var t;try{t=e.then}catch(e){return void this._reject(e)}if(r(t)){var n=this,o=!1;try{t.call(e,function(e){o||(o=!0,n._resolve(e))},function(e){o||(o=!0,n._reject(e))},function(e){n._notify(e)})}catch(e){o||this._reject(e)}return}}this._fulfill(e)}else this._reject(TypeError("Can't resolve promise with itself"))},_fulfill:function(e){this._status>d||(this._status=v,this._value=e,this._callCallbacks(this._fulfilledCallbacks,e),this._fulfilledCallbacks=this._rejectedCallbacks=this._progressCallbacks=void 0)},_reject:function(e){if(!(this._status>d)){if(this._status=p,this._value=e,this._callCallbacks(this._rejectedCallbacks,e),!this._rejectedCallbacks.length){var n=this;t(function(){n._shouldEmitUnhandledRejection&&a(e,n)})}this._fulfilledCallbacks=this._rejectedCallbacks=this._progressCallbacks=void 0}},_notify:function(e){this._callCallbacks(this._progressCallbacks,e)},_addCallbacks:function(e,t,n,i,o){var s;n&&!r(n)?(o=n,n=void 0):i&&!r(i)&&(o=i,i=void 0),n&&(this._shouldEmitUnhandledRejection=!1),this.isRejected()||(s={defer:e,fn:r(t)?t:void 0,ctx:o},this.isFulfilled()?this._callCallbacks([s],this._value):this._fulfilledCallbacks.push(s)),this.isFulfilled()||(s={defer:e,fn:n,ctx:o},this.isRejected()?this._callCallbacks([s],this._value):this._rejectedCallbacks.push(s)),this._status<=d&&this._progressCallbacks.push({defer:e,fn:i,ctx:o})},_callCallbacks:function(e,n){var r=e.length;if(r){this.isResolved();var i=this.isFulfilled(),o=this.isRejected();t(function(){for(var t,s,l,u=0;u<r;)if(s=(t=e[u ]).defer,l=t.fn){var c,a=t.ctx;try{c=a?l.call(a,n):l(n)}catch(e){s.reject(e);continue}i||o?s.resolve(c):s.notify(c)}else i?s.resolve(n):o?s.reject(n):s.notify(n)})}}};var m={cast:function(e){return b.cast(e)},all:function(e){return b.all(e)},allSettled:function(e){return b.allSettled(e)},race:function(e){return b.anyResolved(e)},resolve:function(e){return b.resolve(e)},reject:function(e){return b.reject(e)}};for(var j in m)m.hasOwnProperty(j)&&(_[j]=m[j]);var y,w,b={Deferred:f,Promise:_,defer:function(){return new f},when:function(e,t,n,r,i){return b.cast(e).then(t,n,r,i)},fail:function(e,t,n){return b.when(e,void 0,t,n)},always:function(e,t,n){return b.when(e).always(t,n)},progress:function(e,t,n){return b.when(e).progress(t,n)},spread:function(e,t,n,r){return b.when(e).spread(t,n,r)},done:function(e,t,n,r,i){b.when(e).done(t,n,r,i)},isPromise:function(e){return i(e)&&r(e.then)},cast:function(e){return e&&e._vow?e:b.resolve(e)},valueOf:function(e){return e&&r(e.valueOf)?e.valueOf():e},isFulfilled:function(e){return!e||!r(e.isFulfilled)||e.isFulfilled()},isRejected:function(e){return!(!e||!r(e.isRejected))&&e.isRejected()},isResolved:function(e){return!e||!r(e.isResolved)||e.isResolved()},resolve:function(e){var t=b.defer();return t.resolve(e),t.promise()},fulfill:function(e){var t=b.defer(),n=t.promise();return t.resolve(e),n.isFulfilled()?n:n.then(null,function(e){return e})},reject:function(e){var t=b.defer();return t.reject(e),t.promise()},invoke:function(t,n){var r,i=Math.max(arguments.length-1,0);if(i){r=Array(i);for(var o=0;o<i;)r[o ]=arguments[o]}try{return b.resolve(r?t.apply(e,r):t.call(e))}catch(e){return b.reject(e)}},all:function(e){var t=new f,n=s(e),r=n?l(e):u(e),i=r.length,o=n?[]:{};if(!i)return t.resolve(o),t.promise();var c=i;return b._forEach(e,function(e,n){o[r[n]]=e,--c||t.resolve(o)},t.reject,t.notify,t,r),t.promise()},allResolved:function(e){var t=new f,n=s(e),r=n?l(e):u(e),i=r.length,o=n?[]:{};if(!i)return t.resolve(o),t.promise();var c=function(){--i||t.resolve(e)};return b._forEach(e,c,c,t.notify,t,r),t.promise()},allSettled:function(e){return b.allResolved(e).then(function(){for(var t,n,r,i=s(e),o=i?l(e):u(e),c=i?[]:{},a=o.length,f=0;f<a;)t=o[f ],promise=e[t],n=promise.valueOf(),r=promise.isRejected()?{status:"rejected",reason:n}:{status:"fulfilled",value:n},i?c.push(r):c[t]=r;return c})},allPatiently:function(e){return b.allResolved(e).then(function(){var t,n,r,i,o=s(e),c=o?l(e):u(e),a=c.length,f=0;if(!a)return o?[]:{};for(;f<a;)r=c[f ],i=e[r],b.isRejected(i)?(t||(t=o?[]:{}),o?t.push(i.valueOf()):t[r]=i.valueOf()):t||((n||(n=o?[]:{}))[r]=b.valueOf(i));if(t)throw t;return n})},any:function(e){var t=new f,n=e.length;if(!n)return t.reject(Error()),t.promise();var r,i=0;return b._forEach(e,t.resolve,function(e){i||(r=e), i===n&&t.reject(r)},t.notify,t),t.promise()},anyResolved:function(e){var t=new f;return e.length?(b._forEach(e,t.resolve,t.reject,t.notify,t),t.promise()):(t.reject(Error()),t.promise())},delay:function(e,t){return b.resolve(e).delay(t)},timeout:function(e,t){return b.resolve(e).timeout(t)},_forEach:function(e,t,n,r,i,o){for(var s=o?o.length:e.length,l=0;l<s;)b.when(e[o?o[l]:l],c(t,l),n,r,i), l},TimedOutError:(y="TimedOut",w=function(e){this.name=y,this.message=e},w.prototype=new Error,w)},g=!0;"object"==typeof module&&"object"==typeof module.exports&&(module.exports=b,g=!1),"object"==typeof modules&&r(modules.define)&&(modules.define("vow",function(e){e(b)}),g=!1),"function"==typeof define&&(define(function(e,t,n){n.exports=b}),g=!1),g&&(e.vow=b)}("undefined"!=typeof window?window:global);