vue-asyncx 1.0.3 → 1.1.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/README.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## 特性
2
+
3
+ - 异步函数样板代码减少50%
4
+ - 异步函数相关的函数、变量命名风格统一
5
+ - 良好的 ts 提示支持
6
+ - 单元测试覆盖率 100%
7
+
1
8
  ## 开始
2
9
 
3
10
  ### 安装
@@ -15,8 +22,8 @@ import { submitOrder } from '@/api'
15
22
  import { useAsync } from 'vue-asyncx'
16
23
 
17
24
  /**
18
- * 函数 submit、加载状态 submitLoading
19
- * 随着 useAsync('submit', ...) 调用自动提示
25
+ * 调用 useAsync('submit', ...),
26
+ * submit、submitLoading 自动提示
20
27
  */
21
28
  const {
22
29
  submit,
@@ -33,8 +40,8 @@ import { getUserById } from '@/api'
33
40
  import { useAsyncData } from 'vue-asyncx'
34
41
 
35
42
  /**
36
- * 变量 user、加载状态 queryUserLoading、函数 queryUser
37
- * 随着 useAsyncData('user', ...) 调用自动提示
43
+ * 调用 useAsyncData('user', ...),
44
+ * user、queryUserLoading、queryUser 自动提示
38
45
  */
39
46
  const {
40
47
  user,
@@ -42,15 +49,3 @@ const {
42
49
  queryUser
43
50
  } = useAsyncData('user', () => getUserById('1'), { immediate: true })
44
51
  ```
45
-
46
- ### 优势
47
-
48
- - 单测覆盖率100%
49
- - 在大型项目中统一对下列三者的命名,使项目具备更好的维护性
50
- - 异步函数
51
- - 异步函数调用加载状态
52
- - 异步函数获取的数据
53
- - 通过 ts 提示,函数与变量声明过程无感,直观
54
- - 代码编写过程思路流畅
55
- - 从需要 `submit` 函数开始,书写 `useAsync('submit', ...)`,后续解构均有提示辅助
56
- - 类似的,从需要 `user` 变量开始,书写 `useAsyncData('user', ...)`,后续变量、方法、加载变量均自动提示
@@ -1,4 +1,5 @@
1
1
  import { Ref } from 'vue';
2
+ import { WatchOptions } from 'vue';
2
3
  import { WatchSource } from 'vue';
3
4
 
4
5
  declare type StringDefaultWhenEmpty<S extends string, D extends string> = S extends '' ? D : S;
@@ -20,8 +21,9 @@ declare type UseAsyncDataResult<Fn extends (...args: any) => any, DataName exten
20
21
  };
21
22
 
22
23
  declare type UseAsyncOptions = {
23
- immediate?: boolean;
24
24
  watch?: WatchSource;
25
+ watchOptions?: WatchOptions;
26
+ immediate?: boolean;
25
27
  };
26
28
 
27
29
  declare type UseAsyncResult<Fn extends Function, Name extends string> = {
@@ -1,42 +1,64 @@
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] };
1
+ var h = Object.defineProperty, d = Object.defineProperties;
2
+ var w = Object.getOwnPropertyDescriptors;
3
+ var p = Object.getOwnPropertySymbols;
4
+ var A = Object.prototype.hasOwnProperty, E = Object.prototype.propertyIsEnumerable;
5
+ var u = (n, t, o) => t in n ? h(n, t, { enumerable: !0, configurable: !0, writable: !0, value: o }) : n[t] = o, m = (n, t) => {
6
+ for (var o in t || (t = {}))
7
+ A.call(t, o) && u(n, o, t[o]);
8
+ if (p)
9
+ for (var o of p(t))
10
+ E.call(t, o) && u(n, o, t[o]);
11
+ return n;
12
+ }, y = (n, t) => d(n, w(t));
13
+ import { ref as l, watch as T } from "vue";
14
+ function v(...n) {
15
+ var a;
16
+ if (!Array.isArray(n) || !n.length) throw TypeError("参数错误:未传递");
17
+ const { name: t, fn: o, options: r } = typeof n[0] == "function" ? { name: "method", fn: n[0], options: n[1] } : { name: n[0] || "method", fn: n[1], options: n[2] };
5
18
  if (typeof t != "string") throw TypeError("参数错误:name");
6
- if (typeof r != "function") throw TypeError("参数错误:fn");
7
- const o = a(!1);
8
- function f(...u) {
9
- o.value = !0;
10
- const i = r(...u);
11
- return i instanceof Promise ? i.finally(() => o.value = !1) : o.value = !1, i;
19
+ if (typeof o != "function") throw TypeError("参数错误:fn");
20
+ const i = l(!1);
21
+ function s(...f) {
22
+ i.value = !0;
23
+ const e = o(...f);
24
+ return e instanceof Promise ? e.finally(() => i.value = !1) : i.value = !1, e;
12
25
  }
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
26
+ if (r) {
27
+ const f = () => {
28
+ }, e = Object.assign(
29
+ {},
30
+ "immediate" in r ? { immediate: r.immediate } : {},
31
+ (a = r.watchOptions) != null ? a : {}
32
+ ), { watch: c } = r;
33
+ T(c != null ? c : f, () => s(), e);
34
+ }
35
+ return {
36
+ [t]: s,
37
+ [`${t}Loading`]: i
16
38
  };
17
39
  }
18
- function p(e) {
19
- if (!e) return "";
20
- const t = e[0], r = e.slice(1);
21
- return t.toUpperCase() + r;
40
+ function O(n) {
41
+ if (!n) return "";
42
+ const t = n[0], o = n.slice(1);
43
+ return t.toUpperCase() + o;
22
44
  }
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] };
45
+ function $(...n) {
46
+ if (!Array.isArray(n) || !n.length) throw TypeError("参数错误:未传递");
47
+ const { name: t, fn: o, options: r } = typeof n[0] == "function" ? { name: "data", fn: n[0], options: n[1] } : { name: n[0] || "data", fn: n[1], options: n[2] };
26
48
  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;
49
+ if (typeof o != "function") throw TypeError("参数错误:fn");
50
+ const i = l();
51
+ function s(...f) {
52
+ const e = o(...f);
53
+ return e instanceof Promise ? e.then((c) => i.value = c) : i.value = e, e;
32
54
  }
33
- return {
34
- ...l(`query${p(t)}`, f, n),
35
- [t]: o
36
- };
55
+ const a = v(`query${O(t)}`, s, r);
56
+ return y(m({}, a), {
57
+ [t]: i
58
+ });
37
59
  }
38
60
  export {
39
- l as useAsync,
40
- h as useAsyncData,
41
- l as useAsyncFunction
61
+ v as useAsync,
62
+ $ as useAsyncData,
63
+ v as useAsyncFunction
42
64
  };
@@ -1 +1 @@
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"})});
1
+ (function(t,n){typeof exports=="object"&&typeof module!="undefined"?n(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],n):(t=typeof globalThis!="undefined"?globalThis:t||self,n(t.VueAsyncx={},t.Vue))})(this,function(t,n){"use strict";var T=Object.defineProperty,v=Object.defineProperties;var E=Object.getOwnPropertyDescriptors;var d=Object.getOwnPropertySymbols;var O=Object.prototype.hasOwnProperty,b=Object.prototype.propertyIsEnumerable;var m=(t,n,o)=>n in t?T(t,n,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[n]=o,l=(t,n)=>{for(var o in n||(n={}))O.call(n,o)&&m(t,o,n[o]);if(d)for(var o of d(n))b.call(n,o)&&m(t,o,n[o]);return t},h=(t,n)=>v(t,E(n));function o(...e){var y;if(!Array.isArray(e)||!e.length)throw TypeError("参数错误:未传递");const{name:f,fn:u,options:s}=typeof e[0]=="function"?{name:"method",fn:e[0],options:e[1]}:{name:e[0]||"method",fn:e[1],options:e[2]};if(typeof f!="string")throw TypeError("参数错误:name");if(typeof u!="function")throw TypeError("参数错误:fn");const r=n.ref(!1);function a(...c){r.value=!0;const i=u(...c);return i instanceof Promise?i.finally(()=>r.value=!1):r.value=!1,i}if(s){const c=()=>{},i=Object.assign({},"immediate"in s?{immediate:s.immediate}:{},(y=s.watchOptions)!=null?y:{}),{watch:p}=s;n.watch(p!=null?p:c,()=>a(),i)}return{[f]:a,[`${f}Loading`]:r}}function A(e){if(!e)return"";const f=e[0],u=e.slice(1);return f.toUpperCase()+u}function w(...e){if(!Array.isArray(e)||!e.length)throw TypeError("参数错误:未传递");const{name:f,fn:u,options:s}=typeof e[0]=="function"?{name:"data",fn:e[0],options:e[1]}:{name:e[0]||"data",fn:e[1],options:e[2]};if(typeof f!="string")throw TypeError("参数错误:name");if(typeof u!="function")throw TypeError("参数错误:fn");const r=n.ref();function a(...c){const i=u(...c);return i instanceof Promise?i.then(p=>r.value=p):r.value=i,i}const y=o(`query${A(f)}`,a,s);return h(l({},y),{[f]:r})}t.useAsync=o,t.useAsyncData=w,t.useAsyncFunction=o,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.3",
3
+ "version": "1.1.0",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "types": "dist/vue-asyncx.d.ts",
@@ -15,7 +15,13 @@
15
15
  "require": "./dist/vue-asyncx.umd.cjs"
16
16
  }
17
17
  },
18
- "keywords": [],
18
+ "keywords": [
19
+ "vue",
20
+ "utils",
21
+ "async",
22
+ "vueuse",
23
+ "hooks"
24
+ ],
19
25
  "author": "Xu Yiming",
20
26
  "license": "MIT",
21
27
  "repository": {
@@ -38,6 +44,6 @@
38
44
  "build": "vite build",
39
45
  "test:unit": "vitest",
40
46
  "test:unit:coverage": "vitest run --coverage",
41
- "test": "echo \"Error: no test specified\" && exit 1"
47
+ "test": "pnpm run test:unit"
42
48
  }
43
49
  }