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.
@@ -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 { }
@@ -1,70 +1,94 @@
1
- var w = Object.defineProperty, A = Object.defineProperties;
2
- var v = Object.getOwnPropertyDescriptors;
3
- var y = Object.getOwnPropertySymbols;
4
- var E = Object.prototype.hasOwnProperty, T = Object.prototype.propertyIsEnumerable;
5
- var l = (n, t, o) => t in n ? w(n, t, { enumerable: !0, configurable: !0, writable: !0, value: o }) : n[t] = o, h = (n, t) => {
6
- for (var o in t || (t = {}))
7
- E.call(t, o) && l(n, o, t[o]);
8
- if (y)
9
- for (var o of y(t))
10
- T.call(t, o) && l(n, o, t[o]);
11
- return n;
12
- }, d = (n, t) => A(n, v(t));
13
- import { ref as m, watch as O } from "vue";
14
- function $(...n) {
15
- var p;
16
- if (!Array.isArray(n) || !n.length) throw TypeError("参数错误:未传递");
17
- const { name: t, fn: o, options: i } = typeof n[0] == "function" ? { name: "method", fn: n[0], options: n[1] } : { name: n[0] || "method", fn: n[1], options: n[2] };
18
- if (typeof t != "string") throw TypeError("参数错误:name");
19
- if (typeof o != "function") throw TypeError("参数错误:fn");
20
- const r = m(!1), c = m();
21
- function a(...e) {
22
- const s = () => {
23
- r.value = !0, c.value = e;
24
- }, f = () => {
25
- r.value = !1, c.value = void 0;
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
- s();
28
- const u = o(...e);
29
- return u instanceof Promise ? u.finally(() => f()) : f(), u;
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 (i) {
32
- const e = () => {
33
- }, s = Object.assign(
38
+ if (d) {
39
+ const a = () => {
40
+ }, i = Object.assign(
34
41
  {},
35
- "immediate" in i ? { immediate: i.immediate } : {},
36
- (p = i.watchOptions) != null ? p : {}
37
- ), { watch: f } = i;
38
- O(f != null ? f : e, () => a(), s);
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
- [t]: a,
42
- [`${t}Loading`]: r,
43
- [`${t}Arguments`]: c
48
+ [n]: h,
49
+ [`${n}Loading`]: r,
50
+ [`${n}Arguments`]: u,
51
+ [`${n}Error`]: l
44
52
  };
45
53
  }
46
- function b(n) {
47
- if (!n) return "";
48
- const t = n[0], o = n.slice(1);
49
- return t.toUpperCase() + o;
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 j(...n) {
52
- if (!Array.isArray(n) || !n.length) throw TypeError("参数错误:未传递");
53
- const { name: t, fn: o, options: i } = typeof n[0] == "function" ? { name: "data", fn: n[0], options: n[1] } : { name: n[0] || "data", fn: n[1], options: n[2] };
54
- if (typeof t != "string") throw TypeError("参数错误:name");
55
- if (typeof o != "function") throw TypeError("参数错误:fn");
56
- const r = m();
57
- function c(...p) {
58
- const e = o(...p);
59
- return e instanceof Promise ? e.then((s) => r.value = s) : r.value = e, e;
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
- const a = $(`query${b(t)}`, c, i);
62
- return d(h({}, a), {
63
- [t]: r
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
- $ as useAsync,
68
- j as useAsyncData,
69
- $ as useAsyncFunction
91
+ P as useAsync,
92
+ _ as useAsyncData,
93
+ P as useAsyncFunction
70
94
  };
@@ -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 E=Object.defineProperty,b=Object.defineProperties;var O=Object.getOwnPropertyDescriptors;var l=Object.getOwnPropertySymbols;var j=Object.prototype.hasOwnProperty,P=Object.prototype.propertyIsEnumerable;var h=(t,e,o)=>e in t?E(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o,A=(t,e)=>{for(var o in e||(e={}))j.call(e,o)&&h(t,o,e[o]);if(l)for(var o of l(e))P.call(e,o)&&h(t,o,e[o]);return t},w=(t,e)=>b(t,O(e));function o(...n){var d;if(!Array.isArray(n)||!n.length)throw TypeError("参数错误:未传递");const{name:i,fn:r,options:s}=typeof n[0]=="function"?{name:"method",fn:n[0],options:n[1]}:{name:n[0]||"method",fn:n[1],options:n[2]};if(typeof i!="string")throw TypeError("参数错误:name");if(typeof r!="function")throw TypeError("参数错误:fn");const c=e.ref(!1),p=e.ref();function y(...f){const a=()=>{c.value=!0,p.value=f},u=()=>{c.value=!1,p.value=void 0};a();const m=r(...f);return m instanceof Promise?m.finally(()=>u()):u(),m}if(s){const f=()=>{},a=Object.assign({},"immediate"in s?{immediate:s.immediate}:{},(d=s.watchOptions)!=null?d:{}),{watch:u}=s;e.watch(u!=null?u:f,()=>y(),a)}return{[i]:y,[`${i}Loading`]:c,[`${i}Arguments`]:p}}function T(n){if(!n)return"";const i=n[0],r=n.slice(1);return i.toUpperCase()+r}function v(...n){if(!Array.isArray(n)||!n.length)throw TypeError("参数错误:未传递");const{name:i,fn:r,options:s}=typeof n[0]=="function"?{name:"data",fn:n[0],options:n[1]}:{name:n[0]||"data",fn:n[1],options:n[2]};if(typeof i!="string")throw TypeError("参数错误:name");if(typeof r!="function")throw TypeError("参数错误:fn");const c=e.ref();function p(...d){const f=r(...d);return f instanceof Promise?f.then(a=>c.value=a):c.value=f,f}const y=o(`query${T(i)}`,p,s);return w(A({},y),{[i]:c})}t.useAsync=o,t.useAsyncData=v,t.useAsyncFunction=o,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})});
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"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vue-asyncx",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "types": "dist/vue-asyncx.d.ts",