@axios-use/vue
Advanced tools
Comparing version 0.3.0-alpha.0 to 0.3.0-alpha.1
@@ -1,2 +0,2 @@ | ||
(function(r,c){typeof exports=="object"&&typeof module!="undefined"?c(exports,require("vue"),require("axios")):typeof define=="function"&&define.amd?define(["exports","vue","axios"],c):(r=typeof globalThis!="undefined"?globalThis:r||self,c(r.AxiosUseVue={},r.Vue,r.Axios))})(this,function(r,c,s){"use strict";var X=Object.defineProperty,Y=Object.defineProperties;var z=Object.getOwnPropertyDescriptors;var O=Object.getOwnPropertySymbols;var F=Object.prototype.hasOwnProperty,H=Object.prototype.propertyIsEnumerable;var L=(r,c,s)=>c in r?X(r,c,{enumerable:!0,configurable:!0,writable:!0,value:s}):r[c]=s,D=(r,c)=>{for(var s in c||(c={}))F.call(c,s)&&L(r,s,c[s]);if(O)for(var s of O(c))H.call(c,s)&&L(r,s,c[s]);return r},M=(r,c)=>Y(r,z(c));var V=(r,c,s)=>new Promise((v,S)=>{var w=g=>{try{I(s.next(g))}catch(A){S(A)}},U=g=>{try{I(s.throw(g))}catch(A){S(A)}},I=g=>g.done?v(g.value):Promise.resolve(g.value).then(w,U);I((s=s.apply(r,c)).next())});const v="[@axios-use/vue warn]: getUseRequestConfig() can only be used inside setup() or functional components.",S=Symbol("axios_use_vue_config"),w=(n,e)=>{Number(n.version.split(".")[0])===2?n.mixin({beforeCreate(){if(!this._provided){const a={};Object.defineProperty(this,"_provided",{get:()=>a,set:u=>Object.assign(a,u)})}this._provided[S]=e}}):n.provide(S,e)},U=n=>n==null?void 0:n.data,I=()=>{const n=!!c.getCurrentInstance();n||console.warn(v);const{instance:e=s,getResponseItem:t=U}=n?c.inject(S,{}):{};return{instance:e,getResponseItem:t}},g={install(n,e){w(n,e)}};function A(n){return n}const G=n=>n;function j(n){var f,h,R,C,q,o,i;const e=n,t=n,a=(h=(f=e==null?void 0:e.response)==null?void 0:f.data)!=null?h:t==null?void 0:t.data,u=(o=(q=(R=a==null?void 0:a.code)!=null?R:e==null?void 0:e.code)!=null?q:(C=e==null?void 0:e.response)==null?void 0:C.status)!=null?o:t==null?void 0:t.status,T=(e==null?void 0:e.message)||((i=e==null?void 0:e.response)==null?void 0:i.statusText)||(t==null?void 0:t.statusText);return{code:u,data:a,message:T,isCancel:s.isCancel(n),original:n}}function E(n,e){const t=I(),a=(e==null?void 0:e.instance)||t.instance,u=c.shallowRef([]),T=c.computed(()=>c.unref(u).length>0),{onCompleted:f,onError:h}=e||{},R=o=>{const i=c.unref(u);o&&i.length>0&&(u.value=i.filter(y=>y.token!==o))},C=o=>{const i=c.unref(u);i.length>0&&(i.map(y=>y.cancel(o)),u.value=[])};return c.onUnmounted(()=>{C()}),[(...o)=>{const i=n(...o),y=s.CancelToken.source();return{ready:()=>(u.value=[...c.unref(u),y],a(M(D({},i),{cancelToken:y.token})).then(_=>{R(y.token);const l=e!=null&&e.getResponseItem?e.getResponseItem(_):t.getResponseItem(_);return f==null||f(l,_),[l,_]}).catch(_=>{R(y.token);const l=j(_);throw h==null||h(l),l})),cancel:y.cancel}},{clear:C,hasPending:T}]}function B(n,e){const t=c.ref(e),a=u=>{t.value=n(t.value,u)};return[c.readonly(t),a]}function k(n){return n&&Array.isArray(n)?n.map(e=>c.unref(e)):[]}function J(n){return n&&Array.isArray(n)?n.some(c.isReactive):!1}const N="A new request has been made before completing the last one";function K(n,e){if(n)return e&&typeof e=="function"?e(...n):!0}function Q(n,e){const t=e.type==="success"?e.response:n.response;return{data:e.type==="success"?e.data:n.data,response:t,error:e.type==="error"?e.error:void 0,isLoading:e.type==="start"}}function W(n,e,t){const[a,{clear:u}]=E(n,{onCompleted:t==null?void 0:t.onCompleted,onError:t==null?void 0:t.onError,instance:t==null?void 0:t.instance,getResponseItem:t==null?void 0:t.getResponseItem}),[T,f]=B(Q,D({isLoading:K(e&&k(e),t==null?void 0:t.filter)},t==null?void 0:t.defaultState)),h=(...d)=>{u(N);const{ready:_,cancel:l}=a(...d);return f({type:"start"}),_().then(([m,b])=>{f({type:"success",data:m,response:b})}).catch(m=>{const b=m;b.isCancel||f({type:"error",error:b})}),l},R=(...d)=>V(this,null,function*(){u(N);const{ready:_}=a(...d);try{f({type:"start"});const[l,m]=yield _();return f({type:"success",data:l,response:m}),[l,m]}catch(l){const m=l;throw m.isCancel||f({type:"error",error:m}),l}}),C=(...d)=>t!=null&&t.asyncReq?R(...d):h(...d),q=()=>{const d=k(e||[]);if(typeof(t==null?void 0:t.filter)=="function"?t.filter(...d):!0)return h(...d)},o=d=>{f({type:"reset"}),u(d)},i=c.computed(()=>e&&k(e));return c.watch(i,d=>{d&&q()},{immediate:!0,deep:J(e)}),[c.computed(()=>c.unref(T)),C,q,o]}r._request=A,r.createRequestError=j,r.default=g,r.request=G,r.useRequest=E,r.useResource=W,Object.defineProperties(r,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); | ||
(function(r,c){typeof exports=="object"&&typeof module!="undefined"?c(exports,require("vue"),require("axios")):typeof define=="function"&&define.amd?define(["exports","vue","axios"],c):(r=typeof globalThis!="undefined"?globalThis:r||self,c(r.AxiosUseVue={},r.Vue,r.Axios))})(this,function(r,c,s){"use strict";var X=Object.defineProperty,Y=Object.defineProperties;var z=Object.getOwnPropertyDescriptors;var O=Object.getOwnPropertySymbols;var F=Object.prototype.hasOwnProperty,H=Object.prototype.propertyIsEnumerable;var L=(r,c,s)=>c in r?X(r,c,{enumerable:!0,configurable:!0,writable:!0,value:s}):r[c]=s,D=(r,c)=>{for(var s in c||(c={}))F.call(c,s)&&L(r,s,c[s]);if(O)for(var s of O(c))H.call(c,s)&&L(r,s,c[s]);return r},M=(r,c)=>Y(r,z(c));var V=(r,c,s)=>new Promise((v,S)=>{var w=g=>{try{I(s.next(g))}catch(A){S(A)}},U=g=>{try{I(s.throw(g))}catch(A){S(A)}},I=g=>g.done?v(g.value):Promise.resolve(g.value).then(w,U);I((s=s.apply(r,c)).next())});const v="[@axios-use/vue warn]: getUseRequestConfig() can only be used inside setup() or functional components.",S=Symbol("axios_use_vue_config"),w=(n,e)=>{Number(n.version.split(".")[0])===2?n.mixin({beforeCreate(){if(!this._provided){const a={};Object.defineProperty(this,"_provided",{get:()=>a,set:u=>Object.assign(a,u)})}this._provided[S]=e}}):n.provide(S,e||{})},U=n=>n==null?void 0:n.data,I=()=>{const n=!!c.getCurrentInstance();n||console.warn(v);const{instance:e=s,getResponseItem:t=U}=n?c.inject(S,{}):{};return{instance:e,getResponseItem:t}},g={install(n,e){w(n,e)}};function A(n){return n}const G=n=>n;function j(n){var f,h,R,C,q,l,o;const e=n,t=n,a=(h=(f=e==null?void 0:e.response)==null?void 0:f.data)!=null?h:t==null?void 0:t.data,u=(l=(q=(R=a==null?void 0:a.code)!=null?R:e==null?void 0:e.code)!=null?q:(C=e==null?void 0:e.response)==null?void 0:C.status)!=null?l:t==null?void 0:t.status,T=(e==null?void 0:e.message)||((o=e==null?void 0:e.response)==null?void 0:o.statusText)||(t==null?void 0:t.statusText);return{code:u,data:a,message:T,isCancel:s.isCancel(n),original:n}}function E(n,e){const t=I(),a=(e==null?void 0:e.instance)||t.instance,u=c.shallowRef([]),T=c.computed(()=>c.unref(u).length>0),{onCompleted:f,onError:h}=e||{},R=l=>{const o=c.unref(u);l&&o.length>0&&(u.value=o.filter(y=>y.token!==l))},C=l=>{const o=c.unref(u);o.length>0&&(o.map(y=>y.cancel(l)),u.value=[])};return c.onUnmounted(()=>{C()}),[(...l)=>{const o=n(...l),y=s.CancelToken.source();return{ready:()=>(u.value=[...c.unref(u),y],a(M(D({},o),{cancelToken:y.token})).then(_=>{R(y.token);const i=e!=null&&e.getResponseItem?e.getResponseItem(_):t.getResponseItem(_);return f==null||f(i,_,l),[i,_]}).catch(_=>{R(y.token);const i=j(_);throw h==null||h(i,l),i})),cancel:y.cancel}},{clear:C,hasPending:T}]}function B(n,e){const t=c.ref(e),a=u=>{t.value=n(t.value,u)};return[c.readonly(t),a]}function k(n){return n&&Array.isArray(n)?n.map(e=>c.unref(e)):[]}function J(n){return n&&Array.isArray(n)?n.some(c.isReactive):!1}const N="A new request has been made before completing the last one";function K(n,e){if(n)return e&&typeof e=="function"?e(...n):!0}function Q(n,e){const t=e.type==="success"?e.response:n.response;return{data:e.type==="success"?e.data:n.data,response:t,error:e.type==="error"?e.error:void 0,isLoading:e.type==="start"}}function W(n,e,t){const[a,{clear:u}]=E(n,{onCompleted:t==null?void 0:t.onCompleted,onError:t==null?void 0:t.onError,instance:t==null?void 0:t.instance,getResponseItem:t==null?void 0:t.getResponseItem}),[T,f]=B(Q,D({isLoading:K(e&&k(e),t==null?void 0:t.filter)},t==null?void 0:t.defaultState)),h=(...d)=>{u(N);const{ready:_,cancel:i}=a(...d);return f({type:"start"}),_().then(([m,b])=>{f({type:"success",data:m,response:b})}).catch(m=>{const b=m;b.isCancel||f({type:"error",error:b})}),i},R=(...d)=>V(this,null,function*(){u(N);const{ready:_}=a(...d);try{f({type:"start"});const[i,m]=yield _();return f({type:"success",data:i,response:m}),[i,m]}catch(i){const m=i;throw m.isCancel||f({type:"error",error:m}),i}}),C=(...d)=>t!=null&&t.asyncReq?R(...d):h(...d),q=()=>{const d=k(e||[]);if(typeof(t==null?void 0:t.filter)=="function"?t.filter(...d):!0)return h(...d)},l=d=>{f({type:"reset"}),u(d)},o=c.computed(()=>e&&k(e));return c.watch(o,d=>{d&&q()},{immediate:!0,deep:J(e)}),[c.computed(()=>c.unref(T)),C,q,l]}r._request=A,r.createRequestError=j,r.default=g,r.request=G,r.useRequest=E,r.useResource=W,Object.defineProperties(r,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); | ||
//# sourceMappingURL=axios-use-vue.umd.js.map |
@@ -17,3 +17,3 @@ import { getCurrentInstance as c, inject as r } from "vue"; | ||
} | ||
}) : e.provide(o, t); | ||
}) : e.provide(o, t || {}); | ||
}, u = (e) => e == null ? void 0 : e.data, m = () => { | ||
@@ -20,0 +20,0 @@ const e = !!c(); |
@@ -33,3 +33,3 @@ import type { AxiosRequestConfig, AxiosResponse, AxiosError, Canceler } from "axios"; | ||
*/ | ||
onCompleted?: (data: Payload<T, true>, response: Payload<T>) => void; | ||
onCompleted?: (data: Payload<T, true>, response: Payload<T>, args: Parameters<T>) => void; | ||
/** | ||
@@ -39,3 +39,3 @@ * A callback function that's called when the request encounters one or more errors. | ||
*/ | ||
onError?: (err: RequestError<Payload<T>, BodyData<T>>) => void; | ||
onError?: (err: RequestError<Payload<T>, BodyData<T>>, args: Parameters<T>) => void; | ||
}; | ||
@@ -42,0 +42,0 @@ /** |
@@ -18,21 +18,21 @@ var v = Object.defineProperty, I = Object.defineProperties; | ||
function H(n, e) { | ||
const t = b(), d = (e == null ? void 0 : e.instance) || t.instance, r = w([]), i = y(() => l(r).length > 0), { onCompleted: m, onError: f } = e || {}, g = (o) => { | ||
const s = l(r); | ||
o && s.length > 0 && (r.value = s.filter((c) => c.token !== o)); | ||
}, h = (o) => { | ||
const s = l(r); | ||
s.length > 0 && (s.map((c) => c.cancel(o)), r.value = []); | ||
const t = b(), d = (e == null ? void 0 : e.instance) || t.instance, s = w([]), i = y(() => l(s).length > 0), { onCompleted: m, onError: f } = e || {}, g = (r) => { | ||
const o = l(s); | ||
r && o.length > 0 && (s.value = o.filter((c) => c.token !== r)); | ||
}, h = (r) => { | ||
const o = l(s); | ||
o.length > 0 && (o.map((c) => c.cancel(r)), s.value = []); | ||
}; | ||
return U(() => { | ||
h(); | ||
}), [(...o) => { | ||
const s = n(...o), c = P.CancelToken.source(); | ||
return { ready: () => (r.value = [...l(r), c], d(q(k({}, s), { cancelToken: c.token })).then((a) => { | ||
}), [(...r) => { | ||
const o = n(...r), c = P.CancelToken.source(); | ||
return { ready: () => (s.value = [...l(s), c], d(q(k({}, o), { cancelToken: c.token })).then((u) => { | ||
g(c.token); | ||
const u = e != null && e.getResponseItem ? e.getResponseItem(a) : t.getResponseItem(a); | ||
return m == null || m(u, a), [u, a]; | ||
}).catch((a) => { | ||
const a = e != null && e.getResponseItem ? e.getResponseItem(u) : t.getResponseItem(u); | ||
return m == null || m(a, u, r), [a, u]; | ||
}).catch((u) => { | ||
g(c.token); | ||
const u = j(a); | ||
throw f == null || f(u), u; | ||
const a = j(u); | ||
throw f == null || f(a, r), a; | ||
})), cancel: c.cancel }; | ||
@@ -39,0 +39,0 @@ }, { clear: h, hasPending: i }]; |
{ | ||
"name": "@axios-use/vue", | ||
"version": "0.3.0-alpha.0", | ||
"version": "0.3.0-alpha.1", | ||
"description": "A Vue composition utilities for Axios.", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -138,4 +138,4 @@ <br> | ||
{ | ||
onCompleted: (data, response) => console.info(data, response), | ||
onError: (err) => console.info(err), | ||
onCompleted: (data, response, paramsArgs) => console.info(data, response, paramsArgs), | ||
onError: (err, paramsArgs) => console.info(err, paramsArgs), | ||
}, | ||
@@ -259,4 +259,4 @@ ); | ||
{ | ||
onCompleted: (data, response) => console.info(data, response), | ||
onError: (err) => console.info(err), | ||
onCompleted: (data, response, paramsArgs) => console.info(data, response, paramsArgs), | ||
onError: (err, paramsArgs) => console.info(err, paramsArgs), | ||
}, | ||
@@ -263,0 +263,0 @@ ); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
64568
446