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.
- package/dist/vue-asyncx.d.ts +8 -4
- package/dist/vue-asyncx.js +60 -32
- package/dist/vue-asyncx.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/vue-asyncx.d.ts
CHANGED
|
@@ -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
|
|
7
|
+
declare function useAsync<Fn extends (...args: any) => any>(fn: Fn, options?: UseAsyncOptions): UseAsyncResult<Fn, 'method'>;
|
|
7
8
|
|
|
8
|
-
declare function useAsync<Fn extends
|
|
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
|
|
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 { }
|
package/dist/vue-asyncx.js
CHANGED
|
@@ -1,42 +1,70 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
|
7
|
-
const
|
|
8
|
-
function
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
|
19
|
-
if (!
|
|
20
|
-
const t =
|
|
21
|
-
return t.toUpperCase() +
|
|
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
|
|
24
|
-
if (!Array.isArray(
|
|
25
|
-
const { name: t, fn:
|
|
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
|
|
28
|
-
const
|
|
29
|
-
function
|
|
30
|
-
const
|
|
31
|
-
return
|
|
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
|
-
|
|
34
|
-
|
|
35
|
-
[t]:
|
|
36
|
-
};
|
|
61
|
+
const a = $(`query${b(t)}`, c, i);
|
|
62
|
+
return d(h({}, a), {
|
|
63
|
+
[t]: r
|
|
64
|
+
});
|
|
37
65
|
}
|
|
38
66
|
export {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
67
|
+
$ as useAsync,
|
|
68
|
+
j as useAsyncData,
|
|
69
|
+
$ as useAsyncFunction
|
|
42
70
|
};
|
package/dist/vue-asyncx.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(t,
|
|
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"})});
|