vue-asyncx 1.0.4 → 1.2.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.
@@ -1,11 +1,12 @@
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;
5
6
 
6
- declare function useAsync<Fn extends Function>(fn: Fn, options?: UseAsyncOptions): UseAsyncResult<Fn, 'method'>;
7
+ declare function useAsync<Fn extends (...args: any) => any>(fn: Fn, options?: UseAsyncOptions): UseAsyncResult<Fn, 'method'>;
7
8
 
8
- declare function useAsync<Fn extends Function, Name extends string = string>(name: Name, fn: Fn, options?: UseAsyncOptions): UseAsyncResult<Fn, Name>;
9
+ declare function useAsync<Fn extends (...args: any) => any, Name extends string = string>(name: Name, fn: Fn, options?: UseAsyncOptions): UseAsyncResult<Fn, Name>;
9
10
  export { useAsync }
10
11
  export { useAsync as useAsyncFunction }
11
12
 
@@ -20,14 +21,17 @@ 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
- declare type UseAsyncResult<Fn extends Function, Name extends string> = {
29
+ declare type UseAsyncResult<Fn extends (...args: any) => any, Name extends string> = {
28
30
  [K in StringDefaultWhenEmpty<Name, 'method'>]: Fn;
29
31
  } & {
30
32
  [K in `${StringDefaultWhenEmpty<Name, 'method'>}Loading`]: Ref<boolean>;
33
+ } & {
34
+ [K in `${StringDefaultWhenEmpty<Name, 'method'>}Arguments`]: Ref<Parameters<Fn>>;
31
35
  };
32
36
 
33
37
  export { }
@@ -1,42 +1,70 @@
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 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] };
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 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;
26
+ };
27
+ s();
28
+ const u = o(...e);
29
+ return u instanceof Promise ? u.finally(() => f()) : f(), u;
12
30
  }
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
31
+ if (i) {
32
+ const e = () => {
33
+ }, s = Object.assign(
34
+ {},
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);
39
+ }
40
+ return {
41
+ [t]: a,
42
+ [`${t}Loading`]: r,
43
+ [`${t}Arguments`]: c
16
44
  };
17
45
  }
18
- function p(e) {
19
- if (!e) return "";
20
- const t = e[0], r = e.slice(1);
21
- return t.toUpperCase() + r;
46
+ function b(n) {
47
+ if (!n) return "";
48
+ const t = n[0], o = n.slice(1);
49
+ return t.toUpperCase() + o;
22
50
  }
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] };
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] };
26
54
  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;
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;
32
60
  }
33
- return {
34
- ...l(`query${p(t)}`, f, n),
35
- [t]: o
36
- };
61
+ const a = $(`query${b(t)}`, c, i);
62
+ return d(h({}, a), {
63
+ [t]: r
64
+ });
37
65
  }
38
66
  export {
39
- l as useAsync,
40
- h as useAsyncData,
41
- l as useAsyncFunction
67
+ $ as useAsync,
68
+ j as useAsyncData,
69
+ $ as useAsyncFunction
42
70
  };
@@ -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,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"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vue-asyncx",
3
- "version": "1.0.4",
3
+ "version": "1.2.0",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "types": "dist/vue-asyncx.d.ts",