@axios-use/vue
Advanced tools
Comparing version 0.2.3 to 0.2.4
@@ -0,1 +1,10 @@ | ||
## [0.2.4](https://github.com/axios-use/axios-use-vue/compare/v0.2.3...v0.2.4) (2024-01-08) | ||
### Bug Fixes | ||
* **useRequest:** cancel-sources comparison failed (vue reactivity in depth) ([6e60503](https://github.com/axios-use/axios-use-vue/commit/6e605036235ee0b7f1eedd4c60e4018e46e483da)) | ||
## [0.2.3](https://github.com/axios-use/axios-use-vue/compare/v0.2.2...v0.2.3) (2024-01-04) | ||
@@ -2,0 +11,0 @@ |
@@ -1,2 +0,2 @@ | ||
(function(s,c){typeof exports=="object"&&typeof module!="undefined"?c(exports,require("vue"),require("axios")):typeof define=="function"&&define.amd?define(["exports","vue","axios"],c):(s=typeof globalThis!="undefined"?globalThis:s||self,c(s.AxiosUseVue={},s.Vue,s.Axios))})(this,function(s,c,f){"use strict";var K=Object.defineProperty,Q=Object.defineProperties;var W=Object.getOwnPropertyDescriptors;var b=Object.getOwnPropertySymbols;var X=Object.prototype.hasOwnProperty,Y=Object.prototype.propertyIsEnumerable;var v=(s,c,f)=>c in s?K(s,c,{enumerable:!0,configurable:!0,writable:!0,value:f}):s[c]=f,I=(s,c)=>{for(var f in c||(c={}))X.call(c,f)&&v(s,f,c[f]);if(b)for(var f of b(c))Y.call(c,f)&&v(s,f,c[f]);return s},U=(s,c)=>Q(s,W(c));const k="[@axios-use/vue warn]: getUseRequestConfig() can only be used inside setup() or functional components.",S=Symbol("axios_use_vue_config"),j=(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)},w=n=>n==null?void 0:n.data,D=()=>{const n=!!c.getCurrentInstance();n||console.warn(k);const{instance:e=f,getResponseItem:t=w}=n?c.inject(S,{}):{};return{instance:e,getResponseItem:t}},E={install(n,e){j(n,e)}};function N(n){return n}const O=n=>n;function q(n){var l,g,y,h,R,i,r;const e=n,t=n,a=(g=(l=e==null?void 0:e.response)==null?void 0:l.data)!=null?g:t==null?void 0:t.data,u=(i=(R=(y=a==null?void 0:a.code)!=null?y:e==null?void 0:e.code)!=null?R:(h=e==null?void 0:e.response)==null?void 0:h.status)!=null?i:t==null?void 0:t.status,m=(e==null?void 0:e.message)||((r=e==null?void 0:e.response)==null?void 0:r.statusText)||(t==null?void 0:t.statusText);return{code:u,data:a,message:m,isCancel:f.isCancel(n),original:n}}function A(n,e){const t=D(),a=(e==null?void 0:e.instance)||t.instance,u=c.ref([]),m=c.computed(()=>c.unref(u).length>0),{onCompleted:l,onError:g}=e||{},y=i=>{const r=c.unref(u);i&&r.length>0&&(u.value=r.filter(d=>d.token!==i))},h=i=>{const r=c.unref(u);r.length>0&&(r.map(d=>d.cancel(i)),u.value=[])};return c.onUnmounted(()=>{h()}),[(...i)=>{const r=n(...i),d=f.CancelToken.source();return{ready:()=>(u.value=[...c.unref(u),d],a(U(I({},r),{cancelToken:d.token})).then(o=>{y(d.token);const _=e!=null&&e.getResponseItem?e.getResponseItem(o):t.getResponseItem(o);return l==null||l(_,o),[_,o]}).catch(o=>{y(d.token);const _=q(o);throw g==null||g(_),_})),cancel:d.cancel}},{clear:h,hasPending:m}]}function L(n,e){const t=c.ref(e),a=u=>{t.value=n(t.value,u)};return[c.readonly(t),a]}function C(n){return n&&Array.isArray(n)?n.map(e=>c.unref(e)):[]}function M(n){return n&&Array.isArray(n)?n.some(c.isReactive):!1}const V="A new request has been made before completing the last one";function G(n,e){if(n)return e&&typeof e=="function"?e(...n):!0}function B(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 J(n,e,t){const[a,{clear:u}]=A(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}),[m,l]=L(B,I({isLoading:G(e&&C(e),t==null?void 0:t.filter)},t==null?void 0:t.defaultState)),g=(...r)=>{u(V);const{ready:d,cancel:T}=a(...r);return l({type:"start"}),d().then(([o,_])=>{l({type:"success",data:o,response:_})}).catch(o=>{const _=o;_.isCancel||l({type:"error",error:_})}),T},y=()=>{const r=C(e||[]);if(typeof(t==null?void 0:t.filter)=="function"?t.filter(...r):!0)return g(...r)},h=r=>{l({type:"reset"}),u(r)},R=c.computed(()=>e&&C(e));return c.watch(R,r=>{r&&y()},{immediate:!0,deep:M(e)}),[c.computed(()=>c.unref(m)),g,y,h]}s._request=N,s.createRequestError=q,s.default=E,s.request=O,s.useRequest=A,s.useResource=J,Object.defineProperties(s,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); | ||
(function(s,c){typeof exports=="object"&&typeof module!="undefined"?c(exports,require("vue"),require("axios")):typeof define=="function"&&define.amd?define(["exports","vue","axios"],c):(s=typeof globalThis!="undefined"?globalThis:s||self,c(s.AxiosUseVue={},s.Vue,s.Axios))})(this,function(s,c,f){"use strict";var K=Object.defineProperty,Q=Object.defineProperties;var W=Object.getOwnPropertyDescriptors;var b=Object.getOwnPropertySymbols;var X=Object.prototype.hasOwnProperty,Y=Object.prototype.propertyIsEnumerable;var v=(s,c,f)=>c in s?K(s,c,{enumerable:!0,configurable:!0,writable:!0,value:f}):s[c]=f,I=(s,c)=>{for(var f in c||(c={}))X.call(c,f)&&v(s,f,c[f]);if(b)for(var f of b(c))Y.call(c,f)&&v(s,f,c[f]);return s},U=(s,c)=>Q(s,W(c));const k="[@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)},j=n=>n==null?void 0:n.data,D=()=>{const n=!!c.getCurrentInstance();n||console.warn(k);const{instance:e=f,getResponseItem:t=j}=n?c.inject(S,{}):{};return{instance:e,getResponseItem:t}},E={install(n,e){w(n,e)}};function N(n){return n}const O=n=>n;function q(n){var l,g,h,y,R,i,r;const e=n,t=n,a=(g=(l=e==null?void 0:e.response)==null?void 0:l.data)!=null?g:t==null?void 0:t.data,u=(i=(R=(h=a==null?void 0:a.code)!=null?h:e==null?void 0:e.code)!=null?R:(y=e==null?void 0:e.response)==null?void 0:y.status)!=null?i:t==null?void 0:t.status,m=(e==null?void 0:e.message)||((r=e==null?void 0:e.response)==null?void 0:r.statusText)||(t==null?void 0:t.statusText);return{code:u,data:a,message:m,isCancel:f.isCancel(n),original:n}}function A(n,e){const t=D(),a=(e==null?void 0:e.instance)||t.instance,u=c.shallowRef([]),m=c.computed(()=>c.unref(u).length>0),{onCompleted:l,onError:g}=e||{},h=i=>{const r=c.unref(u);i&&r.length>0&&(u.value=r.filter(d=>d.token!==i))},y=i=>{const r=c.unref(u);r.length>0&&(r.map(d=>d.cancel(i)),u.value=[])};return c.onUnmounted(()=>{y()}),[(...i)=>{const r=n(...i),d=f.CancelToken.source();return{ready:()=>(u.value.push(d),a(U(I({},r),{cancelToken:d.token})).then(o=>{h(d.token);const _=e!=null&&e.getResponseItem?e.getResponseItem(o):t.getResponseItem(o);return l==null||l(_,o),[_,o]}).catch(o=>{h(d.token);const _=q(o);throw g==null||g(_),_})),cancel:d.cancel}},{clear:y,hasPending:m}]}function L(n,e){const t=c.ref(e),a=u=>{t.value=n(t.value,u)};return[c.readonly(t),a]}function C(n){return n&&Array.isArray(n)?n.map(e=>c.unref(e)):[]}function M(n){return n&&Array.isArray(n)?n.some(c.isReactive):!1}const V="A new request has been made before completing the last one";function G(n,e){if(n)return e&&typeof e=="function"?e(...n):!0}function B(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 J(n,e,t){const[a,{clear:u}]=A(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}),[m,l]=L(B,I({isLoading:G(e&&C(e),t==null?void 0:t.filter)},t==null?void 0:t.defaultState)),g=(...r)=>{u(V);const{ready:d,cancel:T}=a(...r);return l({type:"start"}),d().then(([o,_])=>{l({type:"success",data:o,response:_})}).catch(o=>{const _=o;_.isCancel||l({type:"error",error:_})}),T},h=()=>{const r=C(e||[]);if(typeof(t==null?void 0:t.filter)=="function"?t.filter(...r):!0)return g(...r)},y=r=>{l({type:"reset"}),u(r)},R=c.computed(()=>e&&C(e));return c.watch(R,r=>{r&&h()},{immediate:!0,deep:M(e)}),[c.computed(()=>c.unref(m)),g,h,y]}s._request=N,s.createRequestError=q,s.default=E,s.request=O,s.useRequest=A,s.useResource=J,Object.defineProperties(s,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); | ||
//# sourceMappingURL=axios-use-vue.umd.js.map |
var v = Object.defineProperty, I = Object.defineProperties; | ||
var x = Object.getOwnPropertyDescriptors; | ||
var _ = Object.getOwnPropertySymbols; | ||
var R = Object.getOwnPropertySymbols; | ||
var C = Object.prototype.hasOwnProperty, T = Object.prototype.propertyIsEnumerable; | ||
var k = (n, e, t) => e in n ? v(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t, q = (n, e) => { | ||
var _ = (n, e, t) => e in n ? v(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t, k = (n, e) => { | ||
for (var t in e || (e = {})) | ||
C.call(e, t) && k(n, t, e[t]); | ||
if (_) | ||
for (var t of _(e)) | ||
T.call(e, t) && k(n, t, e[t]); | ||
C.call(e, t) && _(n, t, e[t]); | ||
if (R) | ||
for (var t of R(e)) | ||
T.call(e, t) && _(n, t, e[t]); | ||
return n; | ||
}, R = (n, e) => I(n, x(e)); | ||
import { ref as y, computed as U, unref as m, onUnmounted as w } from "vue"; | ||
}, q = (n, e) => I(n, x(e)); | ||
import { shallowRef as w, computed as y, unref as f, onUnmounted as U } from "vue"; | ||
import P from "axios"; | ||
@@ -18,21 +18,21 @@ import { getUseRequestConfig as b } from "./context.js"; | ||
function H(n, e) { | ||
const t = b(), d = (e == null ? void 0 : e.instance) || t.instance, r = y([]), i = U(() => m(r).length > 0), { onCompleted: f, onError: l } = e || {}, g = (o) => { | ||
const s = m(r); | ||
o && s.length > 0 && (r.value = s.filter((c) => c.token !== o)); | ||
const t = b(), d = (e == null ? void 0 : e.instance) || t.instance, s = w([]), i = y(() => f(s).length > 0), { onCompleted: l, onError: m } = e || {}, g = (o) => { | ||
const r = f(s); | ||
o && r.length > 0 && (s.value = r.filter((c) => c.token !== o)); | ||
}, h = (o) => { | ||
const s = m(r); | ||
s.length > 0 && (s.map((c) => c.cancel(o)), r.value = []); | ||
const r = f(s); | ||
r.length > 0 && (r.map((c) => c.cancel(o)), s.value = []); | ||
}; | ||
return w(() => { | ||
return U(() => { | ||
h(); | ||
}), [(...o) => { | ||
const s = n(...o), c = P.CancelToken.source(); | ||
return { ready: () => (r.value = [...m(r), c], d(R(q({}, s), { cancelToken: c.token })).then((u) => { | ||
const r = n(...o), c = P.CancelToken.source(); | ||
return { ready: () => (s.value.push(c), d(q(k({}, r), { cancelToken: c.token })).then((u) => { | ||
g(c.token); | ||
const a = e != null && e.getResponseItem ? e.getResponseItem(u) : t.getResponseItem(u); | ||
return f == null || f(a, u), [a, u]; | ||
return l == null || l(a, u), [a, u]; | ||
}).catch((u) => { | ||
g(c.token); | ||
const a = j(u); | ||
throw l == null || l(a), a; | ||
throw m == null || m(a), a; | ||
})), cancel: c.cancel }; | ||
@@ -39,0 +39,0 @@ }, { clear: h, hasPending: i }]; |
{ | ||
"name": "@axios-use/vue", | ||
"version": "0.2.3", | ||
"version": "0.2.4", | ||
"description": "A Vue composition utilities for Axios.", | ||
@@ -5,0 +5,0 @@ "type": "module", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
60078