UNPKG

@vueuse/integrations

Version:
1 lines 2.05 kB
(function(e,t,n,r){var i=Object.create,a=Object.defineProperty,o=Object.getOwnPropertyDescriptor,s=Object.getOwnPropertyNames,c=Object.getPrototypeOf,l=Object.prototype.hasOwnProperty,u=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=s(t),c=0,u=i.length,d;c<u;c++)d=i[c],!l.call(e,d)&&d!==n&&a(e,d,{get:(e=>t[e]).bind(null,d),enumerable:!(r=o(t,d))||r.enumerable});return e},d=(e,t,n)=>(n=e==null?{}:i(c(e)),u(t||!e||!e.__esModule?a(n,`default`,{value:e,enumerable:!0}):n,e));t=d(t),n=d(n),r=d(r);function f(...e){let i=typeof e[0]==`string`?e[0]:void 0,a=typeof i==`string`?1:0,o={immediate:!!a,shallow:!0,abortPrevious:!0},s={},c=n.default,l=o,u=e=>!!(e!=null&&e.request);e.length>0+a&&(u(e[0+a])?c=e[0+a]:s=e[0+a]),e.length>1+a&&u(e[1+a])&&(c=e[1+a]),(e.length===2+a&&!u(e[1+a])||e.length===3+a)&&(l=e[e.length-1]||o);let{shallow:d,onSuccess:f=t.noop,onError:p=t.noop,immediate:m,resetOnExecute:h=!1}=l,g=l.initialData,_=(0,r.shallowRef)(),v=(d?r.shallowRef:r.ref)(g),y=(0,r.shallowRef)(!1),b=(0,r.shallowRef)(!1),x=(0,r.shallowRef)(!1),S=(0,r.shallowRef)(),C=new AbortController,w=e=>{y.value||!b.value||(C.abort(e),C=new AbortController,x.value=!0,b.value=!1,y.value=!1)},T=e=>{b.value=e,y.value=!e},E=()=>{h&&(v.value=g)},D=()=>new Promise((e,n)=>{(0,t.until)(y).toBe(!0).then(()=>S.value?n(S.value):e(j))}),O={then:(...e)=>D().then(...e),catch:(...e)=>D().catch(...e)},k=0,A=(e=i,t={})=>{S.value=void 0;let r=typeof e==`string`?e:i==null?t.url:i;if(r===void 0)return S.value=new n.AxiosError(n.AxiosError.ERR_INVALID_URL),y.value=!0,O;E(),l.abortPrevious!==!1&&w(),T(!0),k+=1;let a=k;return x.value=!1,c(r,{...s,...typeof e==`object`?e:t,signal:C.signal}).then(e=>{if(x.value)return;_.value=e;let t=e.data;v.value=t,f(t)}).catch(e=>{S.value=e,p(e)}).finally(()=>{var e;(e=l.onFinish)==null||e.call(l),a===k&&T(!1)}),O};m&&i&&A();let j={response:_,data:v,error:S,isFinished:y,isLoading:b,cancel:w,isAborted:x,isCanceled:x,abort:w,execute:A};return{...j,...O}}e.useAxios=f})(this.VueUse=this.VueUse||{},VueUse,axios,Vue);