vue-asyncx 1.2.0 → 1.3.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 +4 -0
- package/dist/vue-asyncx.js +81 -57
- package/dist/vue-asyncx.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/vue-asyncx.d.ts
CHANGED
|
@@ -18,6 +18,8 @@ declare type UseAsyncDataOptions = UseAsyncOptions;
|
|
|
18
18
|
|
|
19
19
|
declare type UseAsyncDataResult<Fn extends (...args: any) => any, DataName extends string> = UseAsyncResult<Fn, `query${Capitalize<(StringDefaultWhenEmpty<DataName, 'data'>)>}`> & {
|
|
20
20
|
[K in (StringDefaultWhenEmpty<DataName, 'data'>)]: Ref<Awaited<ReturnType<Fn>>>;
|
|
21
|
+
} & {
|
|
22
|
+
[K in `${StringDefaultWhenEmpty<DataName, 'data'>}Expired`]: Ref<boolean>;
|
|
21
23
|
};
|
|
22
24
|
|
|
23
25
|
declare type UseAsyncOptions = {
|
|
@@ -32,6 +34,8 @@ declare type UseAsyncResult<Fn extends (...args: any) => any, Name extends strin
|
|
|
32
34
|
[K in `${StringDefaultWhenEmpty<Name, 'method'>}Loading`]: Ref<boolean>;
|
|
33
35
|
} & {
|
|
34
36
|
[K in `${StringDefaultWhenEmpty<Name, 'method'>}Arguments`]: Ref<Parameters<Fn>>;
|
|
37
|
+
} & {
|
|
38
|
+
[K in `${StringDefaultWhenEmpty<Name, 'method'>}Error`]: Ref<any>;
|
|
35
39
|
};
|
|
36
40
|
|
|
37
41
|
export { }
|
package/dist/vue-asyncx.js
CHANGED
|
@@ -1,70 +1,94 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
for (var
|
|
7
|
-
|
|
8
|
-
if (
|
|
9
|
-
for (var
|
|
10
|
-
|
|
11
|
-
return
|
|
12
|
-
},
|
|
13
|
-
import { ref as
|
|
14
|
-
function
|
|
15
|
-
var
|
|
16
|
-
if (!Array.isArray(
|
|
17
|
-
const { name:
|
|
18
|
-
if (typeof
|
|
19
|
-
if (typeof
|
|
20
|
-
const r =
|
|
21
|
-
function
|
|
22
|
-
const s = () => {
|
|
23
|
-
r.value = !0,
|
|
24
|
-
}, f = () => {
|
|
25
|
-
r.value = !1,
|
|
1
|
+
var $ = Object.defineProperty, F = Object.defineProperties;
|
|
2
|
+
var x = Object.getOwnPropertyDescriptors;
|
|
3
|
+
var w = Object.getOwnPropertySymbols;
|
|
4
|
+
var C = Object.prototype.hasOwnProperty, L = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var E = (e, n, t) => n in e ? $(e, n, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[n] = t, A = (e, n) => {
|
|
6
|
+
for (var t in n || (n = {}))
|
|
7
|
+
C.call(n, t) && E(e, t, n[t]);
|
|
8
|
+
if (w)
|
|
9
|
+
for (var t of w(n))
|
|
10
|
+
L.call(n, t) && E(e, t, n[t]);
|
|
11
|
+
return e;
|
|
12
|
+
}, T = (e, n) => F(e, x(n));
|
|
13
|
+
import { ref as p, watch as O, computed as b } from "vue";
|
|
14
|
+
function P(...e) {
|
|
15
|
+
var m;
|
|
16
|
+
if (!Array.isArray(e) || !e.length) throw TypeError("参数错误:未传递");
|
|
17
|
+
const { name: n, fn: t, options: d } = typeof e[0] == "function" ? { name: "method", fn: e[0], options: e[1] } : { name: e[0] || "method", fn: e[1], options: e[2] };
|
|
18
|
+
if (typeof n != "string") throw TypeError("参数错误:name");
|
|
19
|
+
if (typeof t != "function") throw TypeError("参数错误:fn");
|
|
20
|
+
const r = p(!1), u = p(), l = p(), s = { called: 0, finished: 0 };
|
|
21
|
+
function h(...a) {
|
|
22
|
+
const i = ++s.called, o = (c) => {
|
|
23
|
+
l.value = void 0, r.value = !0, u.value = c;
|
|
24
|
+
}, f = (c, { scene: y, sn: v }) => {
|
|
25
|
+
v > s.finished && (s.finished = v), s.called === s.finished && (y === "error" && (l.value = c), r.value = !1, u.value = void 0);
|
|
26
26
|
};
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
o(a);
|
|
28
|
+
try {
|
|
29
|
+
const c = t(...a);
|
|
30
|
+
return c instanceof Promise ? c.then(
|
|
31
|
+
() => f(void 0, { scene: "normal", sn: i }),
|
|
32
|
+
(y) => f(y, { scene: "error", sn: i })
|
|
33
|
+
) : f(void 0, { scene: "normal", sn: i }), c;
|
|
34
|
+
} catch (c) {
|
|
35
|
+
throw f(c, { scene: "error", sn: i }), c;
|
|
36
|
+
}
|
|
30
37
|
}
|
|
31
|
-
if (
|
|
32
|
-
const
|
|
33
|
-
},
|
|
38
|
+
if (d) {
|
|
39
|
+
const a = () => {
|
|
40
|
+
}, i = Object.assign(
|
|
34
41
|
{},
|
|
35
|
-
"immediate" in
|
|
36
|
-
(
|
|
37
|
-
), { watch:
|
|
38
|
-
O(
|
|
42
|
+
"immediate" in d ? { immediate: d.immediate } : {},
|
|
43
|
+
(m = d.watchOptions) != null ? m : {}
|
|
44
|
+
), { watch: o } = d;
|
|
45
|
+
O(o != null ? o : a, () => h(), i);
|
|
39
46
|
}
|
|
40
47
|
return {
|
|
41
|
-
[
|
|
42
|
-
[`${
|
|
43
|
-
[`${
|
|
48
|
+
[n]: h,
|
|
49
|
+
[`${n}Loading`]: r,
|
|
50
|
+
[`${n}Arguments`]: u,
|
|
51
|
+
[`${n}Error`]: l
|
|
44
52
|
};
|
|
45
53
|
}
|
|
46
|
-
function
|
|
47
|
-
if (!
|
|
48
|
-
const
|
|
49
|
-
return
|
|
54
|
+
function j(e) {
|
|
55
|
+
if (!e) return "";
|
|
56
|
+
const n = e[0], t = e.slice(1);
|
|
57
|
+
return n.toUpperCase() + t;
|
|
50
58
|
}
|
|
51
|
-
function
|
|
52
|
-
if (!Array.isArray(
|
|
53
|
-
const { name:
|
|
54
|
-
if (typeof
|
|
55
|
-
if (typeof
|
|
56
|
-
const r =
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
59
|
+
function _(...e) {
|
|
60
|
+
if (!Array.isArray(e) || !e.length) throw TypeError("参数错误:未传递");
|
|
61
|
+
const { name: n, fn: t, options: d } = typeof e[0] == "function" ? { name: "data", fn: e[0], options: e[1] } : { name: e[0] || "data", fn: e[1], options: e[2] };
|
|
62
|
+
if (typeof n != "string") throw TypeError("参数错误:name");
|
|
63
|
+
if (typeof t != "function") throw TypeError("参数错误:fn");
|
|
64
|
+
const r = p({
|
|
65
|
+
// 调用序号
|
|
66
|
+
called: 0,
|
|
67
|
+
// 调用完成序号
|
|
68
|
+
finished: 0,
|
|
69
|
+
// 更新序号
|
|
70
|
+
updated: 0
|
|
71
|
+
}), u = p(), l = b(() => r.value.updated < r.value.finished);
|
|
72
|
+
function s(a, { scene: i, sn: o }) {
|
|
73
|
+
o > r.value.finished && (r.value.finished = o), i === "update" && o > r.value.updated && (u.value = a, r.value.updated = o);
|
|
60
74
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
75
|
+
function h(...a) {
|
|
76
|
+
const i = ++r.value.called;
|
|
77
|
+
try {
|
|
78
|
+
const o = t(...a);
|
|
79
|
+
return o instanceof Promise ? o.then((f) => s(f, { scene: "update", sn: i }), (f) => s(f, { scene: "error", sn: i })) : s(o, { scene: "update", sn: i }), o;
|
|
80
|
+
} catch (o) {
|
|
81
|
+
throw s(o, { scene: "error", sn: i }), o;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
const m = P(`query${j(n)}`, h, d);
|
|
85
|
+
return T(A({}, m), {
|
|
86
|
+
[n]: u,
|
|
87
|
+
[`${n}Expired`]: l
|
|
64
88
|
});
|
|
65
89
|
}
|
|
66
90
|
export {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
91
|
+
P as useAsync,
|
|
92
|
+
_ as useAsyncData,
|
|
93
|
+
P as useAsyncFunction
|
|
70
94
|
};
|
package/dist/vue-asyncx.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(t,e){typeof exports=="object"&&typeof module!="undefined"?e(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],e):(t=typeof globalThis!="undefined"?globalThis:t||self,e(t.VueAsyncx={},t.Vue))})(this,function(t,e){"use strict";var
|
|
1
|
+
(function(t,e){typeof exports=="object"&&typeof module!="undefined"?e(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],e):(t=typeof globalThis!="undefined"?globalThis:t||self,e(t.VueAsyncx={},t.Vue))})(this,function(t,e){"use strict";var j=Object.defineProperty,x=Object.defineProperties;var C=Object.getOwnPropertyDescriptors;var E=Object.getOwnPropertySymbols;var L=Object.prototype.hasOwnProperty,P=Object.prototype.propertyIsEnumerable;var T=(t,e,i)=>e in t?j(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,$=(t,e)=>{for(var i in e||(e={}))L.call(e,i)&&T(t,i,e[i]);if(E)for(var i of E(e))P.call(e,i)&&T(t,i,e[i]);return t},b=(t,e)=>x(t,C(e));function i(...n){var v;if(!Array.isArray(n)||!n.length)throw TypeError("参数错误:未传递");const{name:s,fn:l,options:p}=typeof n[0]=="function"?{name:"method",fn:n[0],options:n[1]}:{name:n[0]||"method",fn:n[1],options:n[2]};if(typeof s!="string")throw TypeError("参数错误:name");if(typeof l!="function")throw TypeError("参数错误:fn");const f=e.ref(!1),h=e.ref(),m=e.ref(),c={called:0,finished:0};function y(...d){const r=++c.called,o=a=>{m.value=void 0,f.value=!0,h.value=a},u=(a,{scene:w,sn:A})=>{A>c.finished&&(c.finished=A),c.called===c.finished&&(w==="error"&&(m.value=a),f.value=!1,h.value=void 0)};o(d);try{const a=l(...d);return a instanceof Promise?a.then(()=>u(void 0,{scene:"normal",sn:r}),w=>u(w,{scene:"error",sn:r})):u(void 0,{scene:"normal",sn:r}),a}catch(a){throw u(a,{scene:"error",sn:r}),a}}if(p){const d=()=>{},r=Object.assign({},"immediate"in p?{immediate:p.immediate}:{},(v=p.watchOptions)!=null?v:{}),{watch:o}=p;e.watch(o!=null?o:d,()=>y(),r)}return{[s]:y,[`${s}Loading`]:f,[`${s}Arguments`]:h,[`${s}Error`]:m}}function F(n){if(!n)return"";const s=n[0],l=n.slice(1);return s.toUpperCase()+l}function O(...n){if(!Array.isArray(n)||!n.length)throw TypeError("参数错误:未传递");const{name:s,fn:l,options:p}=typeof n[0]=="function"?{name:"data",fn:n[0],options:n[1]}:{name:n[0]||"data",fn:n[1],options:n[2]};if(typeof s!="string")throw TypeError("参数错误:name");if(typeof l!="function")throw TypeError("参数错误:fn");const f=e.ref({called:0,finished:0,updated:0}),h=e.ref(),m=e.computed(()=>f.value.updated<f.value.finished);function c(d,{scene:r,sn:o}){o>f.value.finished&&(f.value.finished=o),r==="update"&&o>f.value.updated&&(h.value=d,f.value.updated=o)}function y(...d){const r=++f.value.called;try{const o=l(...d);return o instanceof Promise?o.then(u=>c(u,{scene:"update",sn:r}),u=>c(u,{scene:"error",sn:r})):c(o,{scene:"update",sn:r}),o}catch(o){throw c(o,{scene:"error",sn:r}),o}}const v=i(`query${F(s)}`,y,p);return b($({},v),{[s]:h,[`${s}Expired`]:m})}t.useAsync=i,t.useAsyncData=O,t.useAsyncFunction=i,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})});
|