vue-asyncx 1.5.3 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/vue-asyncx.d.ts +5 -1
- package/dist/vue-asyncx.js +78 -74
- package/dist/vue-asyncx.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/vue-asyncx.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ComputedRef } from 'vue';
|
|
1
2
|
import { Ref } from 'vue';
|
|
2
3
|
import { WatchCallback } from 'vue';
|
|
3
4
|
import { WatchOptions } from 'vue';
|
|
@@ -33,6 +34,7 @@ export declare function useAsyncData<Data = any, Fn extends (...args: any) => Da
|
|
|
33
34
|
export declare function useAsyncData<Data = any, Fn extends (...args: any) => Data | Promise<Data> | PromiseLike<Data> = (...args: any) => Data | Promise<Data> | PromiseLike<Data>, DataName extends string = string>(name: DataName, fn: Fn, options?: UseAsyncDataOptions<Fn>): UseAsyncDataResult<Fn, DataName>;
|
|
34
35
|
|
|
35
36
|
declare interface UseAsyncDataOptions<Fn extends (...args: any) => any> extends UseAsyncOptions<Fn> {
|
|
37
|
+
initialData?: any;
|
|
36
38
|
enhanceFirstArgument?: boolean;
|
|
37
39
|
}
|
|
38
40
|
|
|
@@ -53,7 +55,9 @@ declare type UseAsyncResult<Fn extends (...args: any) => any, Name extends strin
|
|
|
53
55
|
} & {
|
|
54
56
|
[K in `${StringDefaultWhenEmpty<Name, 'method'>}Loading`]: Ref<boolean>;
|
|
55
57
|
} & {
|
|
56
|
-
[K in `${StringDefaultWhenEmpty<Name, 'method'>}Arguments`]:
|
|
58
|
+
[K in `${StringDefaultWhenEmpty<Name, 'method'>}Arguments`]: ComputedRef<Parameters<Fn>>;
|
|
59
|
+
} & {
|
|
60
|
+
[K in `${StringDefaultWhenEmpty<Name, 'method'>}ArgumentFirst`]: ComputedRef<Parameters<Fn>['0']>;
|
|
57
61
|
} & {
|
|
58
62
|
[K in `${StringDefaultWhenEmpty<Name, 'method'>}Error`]: Ref<any>;
|
|
59
63
|
};
|
package/dist/vue-asyncx.js
CHANGED
|
@@ -1,86 +1,90 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
for (var
|
|
7
|
-
|
|
8
|
-
if (
|
|
9
|
-
for (var
|
|
10
|
-
|
|
1
|
+
var b = Object.defineProperty, g = Object.defineProperties;
|
|
2
|
+
var x = Object.getOwnPropertyDescriptors;
|
|
3
|
+
var E = Object.getOwnPropertySymbols;
|
|
4
|
+
var $ = Object.prototype.hasOwnProperty, D = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var B = (e, t, n) => t in e ? b(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n, w = (e, t) => {
|
|
6
|
+
for (var n in t || (t = {}))
|
|
7
|
+
$.call(t, n) && B(e, n, t[n]);
|
|
8
|
+
if (E)
|
|
9
|
+
for (var n of E(t))
|
|
10
|
+
D.call(t, n) && B(e, n, t[n]);
|
|
11
11
|
return e;
|
|
12
|
-
}, C = (e,
|
|
13
|
-
var
|
|
14
|
-
var
|
|
12
|
+
}, C = (e, t) => g(e, x(t));
|
|
13
|
+
var _ = (e, t) => {
|
|
14
|
+
var n = {};
|
|
15
15
|
for (var a in e)
|
|
16
|
-
|
|
17
|
-
if (e != null &&
|
|
18
|
-
for (var a of
|
|
19
|
-
|
|
20
|
-
return
|
|
16
|
+
$.call(e, a) && t.indexOf(a) < 0 && (n[a] = e[a]);
|
|
17
|
+
if (e != null && E)
|
|
18
|
+
for (var a of E(e))
|
|
19
|
+
t.indexOf(a) < 0 && D.call(e, a) && (n[a] = e[a]);
|
|
20
|
+
return n;
|
|
21
21
|
};
|
|
22
|
-
import { ref as
|
|
22
|
+
import { ref as F, computed as H, watch as N } from "vue";
|
|
23
23
|
function j(...e) {
|
|
24
24
|
var v;
|
|
25
25
|
if (!Array.isArray(e) || !e.length) throw TypeError("参数错误:未传递");
|
|
26
|
-
const { name:
|
|
27
|
-
if (typeof
|
|
28
|
-
if (typeof
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
26
|
+
const { name: t, fn: n, options: a } = typeof e[0] == "function" ? { name: "method", fn: e[0], options: e[1] } : { name: e[0] || "method", fn: e[1], options: e[2] };
|
|
27
|
+
if (typeof t != "string") throw TypeError("参数错误:name");
|
|
28
|
+
if (typeof n != "function") throw TypeError("参数错误:fn");
|
|
29
|
+
const m = F(!1), p = F(), U = H(() => {
|
|
30
|
+
var d;
|
|
31
|
+
return (d = p.value) == null ? void 0 : d[0];
|
|
32
|
+
}), s = F(), u = { called: 0, finished: 0 };
|
|
33
|
+
function y(...d) {
|
|
34
|
+
const l = ++u.called, A = (r) => {
|
|
35
|
+
s.value = void 0, m.value = !0, p.value = r;
|
|
33
36
|
}, c = (r, { scene: o, sn: i }) => {
|
|
34
|
-
i > u.finished && (u.finished = i), u.called === u.finished && (o === "error" && (s.value = r),
|
|
37
|
+
i > u.finished && (u.finished = i), u.called === u.finished && (o === "error" && (s.value = r), m.value = !1, p.value = void 0);
|
|
35
38
|
};
|
|
36
|
-
A(
|
|
39
|
+
A(d);
|
|
37
40
|
try {
|
|
38
|
-
const r =
|
|
41
|
+
const r = n(...d);
|
|
39
42
|
return r instanceof Promise ? r.then(
|
|
40
|
-
() => c(void 0, { scene: "normal", sn:
|
|
41
|
-
(o) => c(o, { scene: "error", sn:
|
|
42
|
-
) : c(void 0, { scene: "normal", sn:
|
|
43
|
+
() => c(void 0, { scene: "normal", sn: l }),
|
|
44
|
+
(o) => c(o, { scene: "error", sn: l })
|
|
45
|
+
) : c(void 0, { scene: "normal", sn: l }), r;
|
|
43
46
|
} catch (r) {
|
|
44
|
-
throw c(r, { scene: "error", sn:
|
|
47
|
+
throw c(r, { scene: "error", sn: l }), r;
|
|
45
48
|
}
|
|
46
49
|
}
|
|
47
50
|
if (a) {
|
|
48
|
-
const
|
|
49
|
-
},
|
|
51
|
+
const d = () => {
|
|
52
|
+
}, h = Object.assign(
|
|
50
53
|
{},
|
|
51
54
|
"immediate" in a ? { immediate: a.immediate } : {},
|
|
52
55
|
(v = a.watchOptions) != null ? v : {}
|
|
53
|
-
), { handlerCreator:
|
|
56
|
+
), { handlerCreator: l } = h, A = _(h, ["handlerCreator"]), { watch: c } = a, o = (() => {
|
|
54
57
|
const i = () => y();
|
|
55
|
-
if (typeof
|
|
58
|
+
if (typeof l != "function") return i;
|
|
56
59
|
try {
|
|
57
|
-
const f =
|
|
60
|
+
const f = l(y);
|
|
58
61
|
return typeof f == "function" ? f : i;
|
|
59
62
|
} catch (f) {
|
|
60
63
|
return i;
|
|
61
64
|
}
|
|
62
65
|
})();
|
|
63
|
-
|
|
66
|
+
N(c != null ? c : d, o, A);
|
|
64
67
|
}
|
|
65
68
|
return {
|
|
66
|
-
[
|
|
67
|
-
[`${
|
|
68
|
-
[`${
|
|
69
|
-
[`${
|
|
69
|
+
[t]: y,
|
|
70
|
+
[`${t}Loading`]: m,
|
|
71
|
+
[`${t}Arguments`]: p,
|
|
72
|
+
[`${t}ArgumentFirst`]: U,
|
|
73
|
+
[`${t}Error`]: s
|
|
70
74
|
};
|
|
71
75
|
}
|
|
72
76
|
function G(e) {
|
|
73
77
|
if (!e) return "";
|
|
74
|
-
const
|
|
75
|
-
return
|
|
78
|
+
const t = e[0], n = e.slice(1);
|
|
79
|
+
return t.toUpperCase() + n;
|
|
76
80
|
}
|
|
77
|
-
const
|
|
78
|
-
function
|
|
81
|
+
const L = "__va_fae";
|
|
82
|
+
function z(...e) {
|
|
79
83
|
if (!Array.isArray(e) || !e.length) throw TypeError("参数错误:未传递");
|
|
80
|
-
const { name:
|
|
81
|
-
if (typeof
|
|
82
|
-
if (typeof
|
|
83
|
-
const c = a || {}, { enhanceFirstArgument: p } = c,
|
|
84
|
+
const { name: t, fn: n, options: a } = typeof e[0] == "function" ? { name: "data", fn: e[0], options: e[1] } : { name: e[0] || "data", fn: e[1], options: e[2] };
|
|
85
|
+
if (typeof t != "string") throw TypeError("参数错误:name");
|
|
86
|
+
if (typeof n != "function") throw TypeError("参数错误:fn");
|
|
87
|
+
const c = a || {}, { enhanceFirstArgument: m, initialData: p } = c, U = _(c, ["enhanceFirstArgument", "initialData"]), s = F({
|
|
84
88
|
// 调用序号(即:fn 第 called 次调用)
|
|
85
89
|
called: 0,
|
|
86
90
|
// 完成序号(即:fn 第 finished 次调用完成)
|
|
@@ -89,55 +93,55 @@ function q(...e) {
|
|
|
89
93
|
dataUpdateByCalled: 0,
|
|
90
94
|
// 数据完成更新序号(即:data 数据由第 dataUpdateByFinished 次调用完成后更新)
|
|
91
95
|
dataUpdateByFinished: 0
|
|
92
|
-
}), u =
|
|
96
|
+
}), u = F(p), y = H(() => !(s.value.dataUpdateByFinished >= s.value.finished || s.value.dataUpdateByCalled > s.value.finished));
|
|
93
97
|
function v(r, { sn: o, scene: i }) {
|
|
94
98
|
o < s.value.dataUpdateByCalled || (u.value = r, s.value.dataUpdateByCalled = o, i === "finish" && (s.value.dataUpdateByFinished = o));
|
|
95
99
|
}
|
|
96
|
-
function
|
|
100
|
+
function h(r, { scene: o, sn: i }) {
|
|
97
101
|
o === "normal" && v(r, { sn: i, scene: "finish" }), i > s.value.finished && (s.value.finished = i);
|
|
98
102
|
}
|
|
99
|
-
function
|
|
103
|
+
function d(r, {
|
|
100
104
|
enhanceFirstArgument: o,
|
|
101
105
|
sn: i
|
|
102
106
|
}) {
|
|
103
107
|
if (!o) return r;
|
|
104
|
-
const [f, ...
|
|
108
|
+
const [f, ...O] = r;
|
|
105
109
|
return [C(w({
|
|
106
|
-
[
|
|
110
|
+
[L]: !0
|
|
107
111
|
}, r.length ? { firstArgument: f } : {}), {
|
|
108
112
|
getData: () => u.value,
|
|
109
|
-
updateData: (
|
|
110
|
-
}), ...
|
|
113
|
+
updateData: (T) => (v(T, { sn: i, scene: "update" }), T)
|
|
114
|
+
}), ...O];
|
|
111
115
|
}
|
|
112
|
-
function
|
|
116
|
+
function l(...r) {
|
|
113
117
|
const o = ++s.value.called;
|
|
114
|
-
r =
|
|
118
|
+
r = d(r, { enhanceFirstArgument: m, sn: o });
|
|
115
119
|
try {
|
|
116
|
-
const i =
|
|
120
|
+
const i = n(...r);
|
|
117
121
|
return i instanceof Promise ? i.then(
|
|
118
122
|
// promise 正常结束
|
|
119
|
-
(f) =>
|
|
123
|
+
(f) => h(f, { scene: "normal", sn: o }),
|
|
120
124
|
// promise 出现拒绝
|
|
121
|
-
(f) =>
|
|
122
|
-
) :
|
|
125
|
+
(f) => h(f, { scene: "error", sn: o })
|
|
126
|
+
) : h(i, { scene: "normal", sn: o }), i;
|
|
123
127
|
} catch (i) {
|
|
124
|
-
throw
|
|
128
|
+
throw h(i, { scene: "error", sn: o }), i;
|
|
125
129
|
}
|
|
126
130
|
}
|
|
127
|
-
const A = j(`query${G(
|
|
131
|
+
const A = j(`query${G(t)}`, l, U);
|
|
128
132
|
return C(w({}, A), {
|
|
129
|
-
[
|
|
130
|
-
[`${
|
|
133
|
+
[t]: u,
|
|
134
|
+
[`${t}Expired`]: y
|
|
131
135
|
});
|
|
132
136
|
}
|
|
133
|
-
function
|
|
134
|
-
if (typeof e != "object" || !e || !e[
|
|
135
|
-
const
|
|
136
|
-
return arguments.length === 2 &&
|
|
137
|
+
function I(e, t) {
|
|
138
|
+
if (typeof e != "object" || !e || !e[L]) throw Error("请配置 options.enhanceFirstArgument = true");
|
|
139
|
+
const n = e;
|
|
140
|
+
return arguments.length === 2 && n.firstArgument === void 0 ? C(w({}, n), { firstArgument: t }) : n;
|
|
137
141
|
}
|
|
138
142
|
export {
|
|
139
|
-
|
|
143
|
+
I as unFirstArgumentEnhanced,
|
|
140
144
|
j as useAsync,
|
|
141
|
-
|
|
145
|
+
z as useAsyncData,
|
|
142
146
|
j as useAsyncFunction
|
|
143
147
|
};
|
package/dist/vue-asyncx.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(e,n){typeof exports=="object"&&typeof module!="undefined"?n(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],n):(e=typeof globalThis!="undefined"?globalThis:e||self,n(e.VueAsyncx={},e.Vue))})(this,function(e,n){"use strict";var
|
|
1
|
+
(function(e,n){typeof exports=="object"&&typeof module!="undefined"?n(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],n):(e=typeof globalThis!="undefined"?globalThis:e||self,n(e.VueAsyncx={},e.Vue))})(this,function(e,n){"use strict";var P=Object.defineProperty,q=Object.defineProperties;var x=Object.getOwnPropertyDescriptors;var C=Object.getOwnPropertySymbols;var O=Object.prototype.hasOwnProperty,j=Object.prototype.propertyIsEnumerable;var g=(e,n,a)=>n in e?P(e,n,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[n]=a,U=(e,n)=>{for(var a in n||(n={}))O.call(n,a)&&g(e,a,n[a]);if(C)for(var a of C(n))j.call(n,a)&&g(e,a,n[a]);return e},_=(e,n)=>q(e,x(n));var D=(e,n)=>{var a={};for(var c in e)O.call(e,c)&&n.indexOf(c)<0&&(a[c]=e[c]);if(e!=null&&C)for(var c of C(e))n.indexOf(c)<0&&j.call(e,c)&&(a[c]=e[c]);return a};function a(...t){var w;if(!Array.isArray(t)||!t.length)throw TypeError("参数错误:未传递");const{name:s,fn:u,options:y}=typeof t[0]=="function"?{name:"method",fn:t[0],options:t[1]}:{name:t[0]||"method",fn:t[1],options:t[2]};if(typeof s!="string")throw TypeError("参数错误:name");if(typeof u!="function")throw TypeError("参数错误:fn");const F=n.ref(!1),v=n.ref(),B=n.computed(()=>{var p;return(p=v.value)==null?void 0:p[0]}),f=n.ref(),h={called:0,finished:0};function E(...p){const m=++h.called,T=i=>{f.value=void 0,F.value=!0,v.value=i},d=(i,{scene:o,sn:r})=>{r>h.finished&&(h.finished=r),h.called===h.finished&&(o==="error"&&(f.value=i),F.value=!1,v.value=void 0)};T(p);try{const i=u(...p);return i instanceof Promise?i.then(()=>d(void 0,{scene:"normal",sn:m}),o=>d(o,{scene:"error",sn:m})):d(void 0,{scene:"normal",sn:m}),i}catch(i){throw d(i,{scene:"error",sn:m}),i}}if(y){const p=()=>{},A=Object.assign({},"immediate"in y?{immediate:y.immediate}:{},(w=y.watchOptions)!=null?w:{}),{handlerCreator:m}=A,T=D(A,["handlerCreator"]),{watch:d}=y,o=(()=>{const r=()=>E();if(typeof m!="function")return r;try{const l=m(E);return typeof l=="function"?l:r}catch(l){return r}})();n.watch(d!=null?d:p,o,T)}return{[s]:E,[`${s}Loading`]:F,[`${s}Arguments`]:v,[`${s}ArgumentFirst`]:B,[`${s}Error`]:f}}function c(t){if(!t)return"";const s=t[0],u=t.slice(1);return s.toUpperCase()+u}const $="__va_fae";function H(...t){if(!Array.isArray(t)||!t.length)throw TypeError("参数错误:未传递");const{name:s,fn:u,options:y}=typeof t[0]=="function"?{name:"data",fn:t[0],options:t[1]}:{name:t[0]||"data",fn:t[1],options:t[2]};if(typeof s!="string")throw TypeError("参数错误:name");if(typeof u!="function")throw TypeError("参数错误:fn");const d=y||{},{enhanceFirstArgument:F,initialData:v}=d,B=D(d,["enhanceFirstArgument","initialData"]),f=n.ref({called:0,finished:0,dataUpdateByCalled:0,dataUpdateByFinished:0}),h=n.ref(v),E=n.computed(()=>!(f.value.dataUpdateByFinished>=f.value.finished||f.value.dataUpdateByCalled>f.value.finished));function w(i,{sn:o,scene:r}){o<f.value.dataUpdateByCalled||(h.value=i,f.value.dataUpdateByCalled=o,r==="finish"&&(f.value.dataUpdateByFinished=o))}function A(i,{scene:o,sn:r}){o==="normal"&&w(i,{sn:r,scene:"finish"}),r>f.value.finished&&(f.value.finished=r)}function p(i,{enhanceFirstArgument:o,sn:r}){if(!o)return i;const[l,...N]=i;return[_(U({[$]:!0},i.length?{firstArgument:l}:{}),{getData:()=>h.value,updateData:b=>(w(b,{sn:r,scene:"update"}),b)}),...N]}function m(...i){const o=++f.value.called;i=p(i,{enhanceFirstArgument:F,sn:o});try{const r=u(...i);return r instanceof Promise?r.then(l=>A(l,{scene:"normal",sn:o}),l=>A(l,{scene:"error",sn:o})):A(r,{scene:"normal",sn:o}),r}catch(r){throw A(r,{scene:"error",sn:o}),r}}const T=a(`query${c(s)}`,m,B);return _(U({},T),{[s]:h,[`${s}Expired`]:E})}function L(t,s){if(typeof t!="object"||!t||!t[$])throw Error("请配置 options.enhanceFirstArgument = true");const u=t;return arguments.length===2&&u.firstArgument===void 0?_(U({},u),{firstArgument:s}):u}e.unFirstArgumentEnhanced=L,e.useAsync=a,e.useAsyncData=H,e.useAsyncFunction=a,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})});
|