vue-asyncx 1.0.2 → 1.0.3

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/README.md CHANGED
@@ -42,3 +42,15 @@ const {
42
42
  queryUser
43
43
  } = useAsyncData('user', () => getUserById('1'), { immediate: true })
44
44
  ```
45
+
46
+ ### 优势
47
+
48
+ - 单测覆盖率100%
49
+ - 在大型项目中统一对下列三者的命名,使项目具备更好的维护性
50
+ - 异步函数
51
+ - 异步函数调用加载状态
52
+ - 异步函数获取的数据
53
+ - 通过 ts 提示,函数与变量声明过程无感,直观
54
+ - 代码编写过程思路流畅
55
+ - 从需要 `submit` 函数开始,书写 `useAsync('submit', ...)`,后续解构均有提示辅助
56
+ - 类似的,从需要 `user` 变量开始,书写 `useAsyncData('user', ...)`,后续变量、方法、加载变量均自动提示
@@ -3,9 +3,11 @@ import { WatchSource } from 'vue';
3
3
 
4
4
  declare type StringDefaultWhenEmpty<S extends string, D extends string> = S extends '' ? D : S;
5
5
 
6
- export declare function useAsync<Fn extends Function>(fn: Fn, options?: UseAsyncOptions): UseAsyncResult<Fn, 'method'>;
6
+ declare function useAsync<Fn extends Function>(fn: Fn, options?: UseAsyncOptions): UseAsyncResult<Fn, 'method'>;
7
7
 
8
- export declare function useAsync<Fn extends Function, Name extends string = string>(name: Name, fn: Fn, options?: UseAsyncOptions): UseAsyncResult<Fn, Name>;
8
+ declare function useAsync<Fn extends Function, Name extends string = string>(name: Name, fn: Fn, options?: UseAsyncOptions): UseAsyncResult<Fn, Name>;
9
+ export { useAsync }
10
+ export { useAsync as useAsyncFunction }
9
11
 
10
12
  export declare function useAsyncData<Data = any, Fn extends (...args: any) => Data | Promise<Data> | PromiseLike<Data> = (...args: any) => Data | Promise<Data> | PromiseLike<Data>>(fn: Fn, options?: UseAsyncDataOptions): UseAsyncDataResult<Fn, 'data'>;
11
13
 
@@ -1,114 +1,42 @@
1
- import { ref as p, watch as $ } from "vue";
2
- var C = typeof global == "object" && global && global.Object === Object && global, E = typeof self == "object" && self && self.Object === Object && self, P = C || E || Function("return this")(), i = P.Symbol, g = Object.prototype, M = g.hasOwnProperty, k = g.toString, u = i ? i.toStringTag : void 0;
3
- function x(r) {
4
- var e = M.call(r, u), n = r[u];
5
- try {
6
- r[u] = void 0;
7
- var t = !0;
8
- } catch {
9
- }
10
- var o = k.call(r);
11
- return t && (e ? r[u] = n : delete r[u]), o;
12
- }
13
- var F = Object.prototype, U = F.toString;
14
- function N(r) {
15
- return U.call(r);
16
- }
17
- var H = "[object Null]", I = "[object Undefined]", b = i ? i.toStringTag : void 0;
18
- function J(r) {
19
- return r == null ? r === void 0 ? I : H : b && b in Object(r) ? x(r) : N(r);
20
- }
21
- function V(r) {
22
- return r != null && typeof r == "object";
23
- }
24
- var q = "[object Symbol]";
25
- function G(r) {
26
- return typeof r == "symbol" || V(r) && J(r) == q;
27
- }
28
- function L(r, e) {
29
- for (var n = -1, t = r == null ? 0 : r.length, o = Array(t); ++n < t; )
30
- o[n] = e(r[n], n, r);
31
- return o;
32
- }
33
- var W = Array.isArray, Z = 1 / 0, y = i ? i.prototype : void 0, m = y ? y.toString : void 0;
34
- function h(r) {
35
- if (typeof r == "string")
36
- return r;
37
- if (W(r))
38
- return L(r, h) + "";
39
- if (G(r))
40
- return m ? m.call(r) : "";
41
- var e = r + "";
42
- return e == "0" && 1 / r == -Z ? "-0" : e;
43
- }
44
- function z(r) {
45
- return r == null ? "" : h(r);
46
- }
47
- function D(r, e, n) {
48
- var t = -1, o = r.length;
49
- e < 0 && (e = -e > o ? 0 : o + e), n = n > o ? o : n, n < 0 && (n += o), o = e > n ? 0 : n - e >>> 0, e >>>= 0;
50
- for (var f = Array(o); ++t < o; )
51
- f[t] = r[t + e];
52
- return f;
53
- }
54
- function Y(r, e, n) {
55
- var t = r.length;
56
- return n = n === void 0 ? t : n, !e && n >= t ? r : D(r, e, n);
57
- }
58
- var B = "\\ud800-\\udfff", K = "\\u0300-\\u036f", Q = "\\ufe20-\\ufe2f", X = "\\u20d0-\\u20ff", _ = K + Q + X, rr = "\\ufe0e\\ufe0f", er = "\\u200d", nr = RegExp("[" + er + B + _ + rr + "]");
59
- function S(r) {
60
- return nr.test(r);
61
- }
62
- function tr(r) {
63
- return r.split("");
64
- }
65
- var T = "\\ud800-\\udfff", or = "\\u0300-\\u036f", fr = "\\ufe20-\\ufe2f", ir = "\\u20d0-\\u20ff", ar = or + fr + ir, ur = "\\ufe0e\\ufe0f", cr = "[" + T + "]", s = "[" + ar + "]", l = "\\ud83c[\\udffb-\\udfff]", sr = "(?:" + s + "|" + l + ")", j = "[^" + T + "]", v = "(?:\\ud83c[\\udde6-\\uddff]){2}", A = "[\\ud800-\\udbff][\\udc00-\\udfff]", lr = "\\u200d", O = sr + "?", R = "[" + ur + "]?", dr = "(?:" + lr + "(?:" + [j, v, A].join("|") + ")" + R + O + ")*", br = R + O + dr, yr = "(?:" + [j + s + "?", s, v, A, cr].join("|") + ")", mr = RegExp(l + "(?=" + l + ")|" + yr + br, "g");
66
- function pr(r) {
67
- return r.match(mr) || [];
68
- }
69
- function gr(r) {
70
- return S(r) ? pr(r) : tr(r);
71
- }
72
- function hr(r) {
73
- return function(e) {
74
- e = z(e);
75
- var n = S(e) ? gr(e) : void 0, t = n ? n[0] : e.charAt(0), o = n ? Y(n, 1).join("") : e.slice(1);
76
- return t[r]() + o;
77
- };
78
- }
79
- var Sr = hr("toUpperCase");
80
- function Tr(...r) {
81
- if (!Array.isArray(r) || !r.length) throw TypeError("参数错误:未传递");
82
- const { name: e, fn: n, options: t } = typeof r[0] == "function" ? { name: "method", fn: r[0], options: r[1] } : { name: r[0] || "method", fn: r[1], options: r[2] };
83
- if (typeof e != "string") throw TypeError("参数错误:name");
84
- if (typeof n != "function") throw TypeError("参数错误:fn");
85
- const o = p(!1);
86
- function f(...d) {
1
+ import { ref as a, watch as y } from "vue";
2
+ function l(...e) {
3
+ if (!Array.isArray(e) || !e.length) throw TypeError("参数错误:未传递");
4
+ const { name: t, fn: r, options: n } = typeof e[0] == "function" ? { name: "method", fn: e[0], options: e[1] } : { name: e[0] || "method", fn: e[1], options: e[2] };
5
+ if (typeof t != "string") throw TypeError("参数错误:name");
6
+ if (typeof r != "function") throw TypeError("参数错误:fn");
7
+ const o = a(!1);
8
+ function f(...u) {
87
9
  o.value = !0;
88
- const a = n(...d);
89
- return a instanceof Promise ? a.finally(() => o.value = !1) : o.value = !1, a;
10
+ const i = r(...u);
11
+ return i instanceof Promise ? i.finally(() => o.value = !1) : o.value = !1, i;
90
12
  }
91
- return t != null && t.watch ? $(t.watch, () => f(), { immediate: t == null ? void 0 : t.immediate }) : t != null && t.immediate && f(), {
92
- [e]: f,
93
- [`${e}Loading`]: o
13
+ return n != null && n.watch ? y(n.watch, () => f(), { immediate: n == null ? void 0 : n.immediate }) : n != null && n.immediate && f(), {
14
+ [t]: f,
15
+ [`${t}Loading`]: o
94
16
  };
95
17
  }
96
- function vr(...r) {
97
- if (!Array.isArray(r) || !r.length) throw TypeError("参数错误:未传递");
98
- const { name: e, fn: n, options: t } = typeof r[0] == "function" ? { name: "data", fn: r[0], options: r[1] } : { name: r[0] || "data", fn: r[1], options: r[2] };
99
- if (typeof e != "string") throw TypeError("参数错误:name");
100
- if (typeof n != "function") throw TypeError("参数错误:fn");
101
- const o = p();
102
- function f(...a) {
103
- const c = n(...a);
104
- return c instanceof Promise ? c.then((w) => o.value = w) : o.value = c, c;
18
+ function p(e) {
19
+ if (!e) return "";
20
+ const t = e[0], r = e.slice(1);
21
+ return t.toUpperCase() + r;
22
+ }
23
+ function h(...e) {
24
+ if (!Array.isArray(e) || !e.length) throw TypeError("参数错误:未传递");
25
+ const { name: t, fn: r, options: n } = typeof e[0] == "function" ? { name: "data", fn: e[0], options: e[1] } : { name: e[0] || "data", fn: e[1], options: e[2] };
26
+ if (typeof t != "string") throw TypeError("参数错误:name");
27
+ if (typeof r != "function") throw TypeError("参数错误:fn");
28
+ const o = a();
29
+ function f(...i) {
30
+ const c = r(...i);
31
+ return c instanceof Promise ? c.then((m) => o.value = m) : o.value = c, c;
105
32
  }
106
33
  return {
107
- ...Tr(`query${Sr(e)}`, f, t),
108
- [e]: o
34
+ ...l(`query${p(t)}`, f, n),
35
+ [t]: o
109
36
  };
110
37
  }
111
38
  export {
112
- Tr as useAsync,
113
- vr as useAsyncData
39
+ l as useAsync,
40
+ h as useAsyncData,
41
+ l as useAsyncFunction
114
42
  };
@@ -1 +1 @@
1
- (function(i,u){typeof exports=="object"&&typeof module<"u"?u(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],u):(i=typeof globalThis<"u"?globalThis:i||self,u(i.VueAsyncx={},i.Vue))})(this,function(i,u){"use strict";var C=typeof global=="object"&&global&&global.Object===Object&&global,P=typeof self=="object"&&self&&self.Object===Object&&self,E=C||P||Function("return this")(),a=E.Symbol,b=Object.prototype,M=b.hasOwnProperty,x=b.toString,c=a?a.toStringTag:void 0;function k(e){var r=M.call(e,c),n=e[c];try{e[c]=void 0;var t=!0}catch{}var o=x.call(e);return t&&(r?e[c]=n:delete e[c]),o}var F=Object.prototype,U=F.toString;function V(e){return U.call(e)}var N="[object Null]",q="[object Undefined]",m=a?a.toStringTag:void 0;function H(e){return e==null?e===void 0?q:N:m&&m in Object(e)?k(e):V(e)}function I(e){return e!=null&&typeof e=="object"}var J="[object Symbol]";function D(e){return typeof e=="symbol"||I(e)&&H(e)==J}function G(e,r){for(var n=-1,t=e==null?0:e.length,o=Array(t);++n<t;)o[n]=r(e[n],n,e);return o}var L=Array.isArray,W=1/0,p=a?a.prototype:void 0,g=p?p.toString:void 0;function h(e){if(typeof e=="string")return e;if(L(e))return G(e,h)+"";if(D(e))return g?g.call(e):"";var r=e+"";return r=="0"&&1/e==-W?"-0":r}function Z(e){return e==null?"":h(e)}function z(e,r,n){var t=-1,o=e.length;r<0&&(r=-r>o?0:o+r),n=n>o?o:n,n<0&&(n+=o),o=r>n?0:n-r>>>0,r>>>=0;for(var f=Array(o);++t<o;)f[t]=e[t+r];return f}function Y(e,r,n){var t=e.length;return n=n===void 0?t:n,!r&&n>=t?e:z(e,r,n)}var B="\\ud800-\\udfff",K="\\u0300-\\u036f",Q="\\ufe20-\\ufe2f",X="\\u20d0-\\u20ff",_=K+Q+X,ee="\\ufe0e\\ufe0f",re="\\u200d",ne=RegExp("["+re+B+_+ee+"]");function T(e){return ne.test(e)}function te(e){return e.split("")}var S="\\ud800-\\udfff",oe="\\u0300-\\u036f",fe="\\ufe20-\\ufe2f",ie="\\u20d0-\\u20ff",ue=oe+fe+ie,ae="\\ufe0e\\ufe0f",ce="["+S+"]",d="["+ue+"]",y="\\ud83c[\\udffb-\\udfff]",se="(?:"+d+"|"+y+")",j="[^"+S+"]",v="(?:\\ud83c[\\udde6-\\uddff]){2}",A="[\\ud800-\\udbff][\\udc00-\\udfff]",le="\\u200d",O=se+"?",R="["+ae+"]?",de="(?:"+le+"(?:"+[j,v,A].join("|")+")"+R+O+")*",ye=R+O+de,be="(?:"+[j+d+"?",d,v,A,ce].join("|")+")",me=RegExp(y+"(?="+y+")|"+be+ye,"g");function pe(e){return e.match(me)||[]}function ge(e){return T(e)?pe(e):te(e)}function he(e){return function(r){r=Z(r);var n=T(r)?ge(r):void 0,t=n?n[0]:r.charAt(0),o=n?Y(n,1).join(""):r.slice(1);return t[e]()+o}}var Te=he("toUpperCase");function w(...e){if(!Array.isArray(e)||!e.length)throw TypeError("参数错误:未传递");const{name:r,fn:n,options:t}=typeof e[0]=="function"?{name:"method",fn:e[0],options:e[1]}:{name:e[0]||"method",fn:e[1],options:e[2]};if(typeof r!="string")throw TypeError("参数错误:name");if(typeof n!="function")throw TypeError("参数错误:fn");const o=u.ref(!1);function f(...$){o.value=!0;const s=n(...$);return s instanceof Promise?s.finally(()=>o.value=!1):o.value=!1,s}return t!=null&&t.watch?u.watch(t.watch,()=>f(),{immediate:t==null?void 0:t.immediate}):t!=null&&t.immediate&&f(),{[r]:f,[`${r}Loading`]:o}}function Se(...e){if(!Array.isArray(e)||!e.length)throw TypeError("参数错误:未传递");const{name:r,fn:n,options:t}=typeof e[0]=="function"?{name:"data",fn:e[0],options:e[1]}:{name:e[0]||"data",fn:e[1],options:e[2]};if(typeof r!="string")throw TypeError("参数错误:name");if(typeof n!="function")throw TypeError("参数错误:fn");const o=u.ref();function f(...s){const l=n(...s);return l instanceof Promise?l.then(je=>o.value=je):o.value=l,l}return{...w(`query${Te(r)}`,f,t),[r]:o}}i.useAsync=w,i.useAsyncData=Se,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})});
1
+ (function(t,f){typeof exports=="object"&&typeof module<"u"?f(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],f):(t=typeof globalThis<"u"?globalThis:t||self,f(t.VueAsyncx={},t.Vue))})(this,function(t,f){"use strict";function s(...e){if(!Array.isArray(e)||!e.length)throw TypeError("参数错误:未传递");const{name:o,fn:r,options:n}=typeof e[0]=="function"?{name:"method",fn:e[0],options:e[1]}:{name:e[0]||"method",fn:e[1],options:e[2]};if(typeof o!="string")throw TypeError("参数错误:name");if(typeof r!="function")throw TypeError("参数错误:fn");const i=f.ref(!1);function u(...y){i.value=!0;const c=r(...y);return c instanceof Promise?c.finally(()=>i.value=!1):i.value=!1,c}return n!=null&&n.watch?f.watch(n.watch,()=>u(),{immediate:n==null?void 0:n.immediate}):n!=null&&n.immediate&&u(),{[o]:u,[`${o}Loading`]:i}}function d(e){if(!e)return"";const o=e[0],r=e.slice(1);return o.toUpperCase()+r}function l(...e){if(!Array.isArray(e)||!e.length)throw TypeError("参数错误:未传递");const{name:o,fn:r,options:n}=typeof e[0]=="function"?{name:"data",fn:e[0],options:e[1]}:{name:e[0]||"data",fn:e[1],options:e[2]};if(typeof o!="string")throw TypeError("参数错误:name");if(typeof r!="function")throw TypeError("参数错误:fn");const i=f.ref();function u(...c){const a=r(...c);return a instanceof Promise?a.then(m=>i.value=m):i.value=a,a}return{...s(`query${d(o)}`,u,n),[o]:i}}t.useAsync=s,t.useAsyncData=l,t.useAsyncFunction=s,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.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "types": "dist/vue-asyncx.d.ts",
@@ -28,15 +28,12 @@
28
28
  "jsdom": "^24.1.1",
29
29
  "typescript": "^5.5.4",
30
30
  "vite": "^5.3.4",
31
- "vite-plugin-dts": "4.0.0-beta.1"
31
+ "vite-plugin-dts": "4.0.0-beta.1",
32
+ "vitest": "^2.0.4"
32
33
  },
33
34
  "peerDependencies": {
34
35
  "vue": ">=3.0.0"
35
36
  },
36
- "dependencies": {
37
- "lodash-es": "^4.17.21",
38
- "vitest": "^2.0.4"
39
- },
40
37
  "scripts": {
41
38
  "build": "vite build",
42
39
  "test:unit": "vitest",