@varlet/axle 0.10.3 → 0.11.0-alpha.1747141760435
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/lib/use.cjs +12 -1
- package/lib/use.d.cts +4 -2
- package/lib/use.d.ts +4 -2
- package/lib/use.js +13 -2
- package/package.json +1 -1
package/lib/use.cjs
CHANGED
|
@@ -91,12 +91,18 @@ function normalizeValueGetter(valueGetter) {
|
|
|
91
91
|
return (0, import_rattail.isFunction)(valueGetter) ? valueGetter() : valueGetter;
|
|
92
92
|
}
|
|
93
93
|
function createUseAxle(options) {
|
|
94
|
-
const {
|
|
94
|
+
const {
|
|
95
|
+
axle,
|
|
96
|
+
onTransform: defaultOnTransform,
|
|
97
|
+
immediate: defaultImmediate = true,
|
|
98
|
+
abortOnUnmount: defaultAbortOnUnmount = true
|
|
99
|
+
} = options;
|
|
95
100
|
const useAxle = (options2) => {
|
|
96
101
|
const {
|
|
97
102
|
url: initialUrlOrGetter,
|
|
98
103
|
method,
|
|
99
104
|
immediate = defaultImmediate,
|
|
105
|
+
abortOnUnmount = defaultAbortOnUnmount,
|
|
100
106
|
value: initialValue,
|
|
101
107
|
resetValue: initialResetValue,
|
|
102
108
|
cloneResetValue: initialCloneResetValue,
|
|
@@ -192,6 +198,11 @@ function createUseAxle(options) {
|
|
|
192
198
|
config: normalizeValueGetter(initialConfigOrGetter)
|
|
193
199
|
});
|
|
194
200
|
}
|
|
201
|
+
if (abortOnUnmount) {
|
|
202
|
+
(0, import_vue4.onUnmounted)(() => {
|
|
203
|
+
abort();
|
|
204
|
+
});
|
|
205
|
+
}
|
|
195
206
|
function resetValue(options3 = {}) {
|
|
196
207
|
var _a, _b;
|
|
197
208
|
const cloneResetValue = (_b = (_a = options3.cloneResetValue) != null ? _a : initialCloneResetValue) != null ? _b : false;
|
package/lib/use.d.cts
CHANGED
|
@@ -37,11 +37,12 @@ interface UseAxleOptions<V = any, R = any, P = Record<string, any>, D = Record<s
|
|
|
37
37
|
url: string | (() => string);
|
|
38
38
|
method: RunnerMethod;
|
|
39
39
|
value?: V;
|
|
40
|
-
|
|
40
|
+
immediate?: boolean;
|
|
41
41
|
resetValue?: boolean;
|
|
42
42
|
cloneResetValue?: boolean | ((value: V) => V);
|
|
43
|
-
|
|
43
|
+
abortOnUnmount?: boolean;
|
|
44
44
|
config?: AxleRequestConfig<D> | (() => AxleRequestConfig<D>);
|
|
45
|
+
params?: P | (() => P);
|
|
45
46
|
onBefore?(refs: UseAxleRefs<V>): void;
|
|
46
47
|
onAfter?(refs: UseAxleRefs<V>): void;
|
|
47
48
|
onTransform?(response: R, refs: UseAxleRefs<V>): V | Promise<V>;
|
|
@@ -55,6 +56,7 @@ type UseAxleInstance<V, R, P, D> = [value: Ref<V>, run: Run<V, R, P, D>, extra:
|
|
|
55
56
|
interface CreateUseAxleOptions {
|
|
56
57
|
axle: AxleInstance;
|
|
57
58
|
immediate?: boolean;
|
|
59
|
+
abortOnUnmount?: boolean;
|
|
58
60
|
onTransform?(response: any, refs: any): any;
|
|
59
61
|
}
|
|
60
62
|
type UseAxle = <V = any, R = any, P = Record<string, any>, D = Record<string, any>>(options: UseAxleOptions<V, R, P, D>) => UseAxleInstance<V, R, P, D>;
|
package/lib/use.d.ts
CHANGED
|
@@ -37,11 +37,12 @@ interface UseAxleOptions<V = any, R = any, P = Record<string, any>, D = Record<s
|
|
|
37
37
|
url: string | (() => string);
|
|
38
38
|
method: RunnerMethod;
|
|
39
39
|
value?: V;
|
|
40
|
-
|
|
40
|
+
immediate?: boolean;
|
|
41
41
|
resetValue?: boolean;
|
|
42
42
|
cloneResetValue?: boolean | ((value: V) => V);
|
|
43
|
-
|
|
43
|
+
abortOnUnmount?: boolean;
|
|
44
44
|
config?: AxleRequestConfig<D> | (() => AxleRequestConfig<D>);
|
|
45
|
+
params?: P | (() => P);
|
|
45
46
|
onBefore?(refs: UseAxleRefs<V>): void;
|
|
46
47
|
onAfter?(refs: UseAxleRefs<V>): void;
|
|
47
48
|
onTransform?(response: R, refs: UseAxleRefs<V>): V | Promise<V>;
|
|
@@ -55,6 +56,7 @@ type UseAxleInstance<V, R, P, D> = [value: Ref<V>, run: Run<V, R, P, D>, extra:
|
|
|
55
56
|
interface CreateUseAxleOptions {
|
|
56
57
|
axle: AxleInstance;
|
|
57
58
|
immediate?: boolean;
|
|
59
|
+
abortOnUnmount?: boolean;
|
|
58
60
|
onTransform?(response: any, refs: any): any;
|
|
59
61
|
}
|
|
60
62
|
type UseAxle = <V = any, R = any, P = Record<string, any>, D = Record<string, any>>(options: UseAxleOptions<V, R, P, D>) => UseAxleInstance<V, R, P, D>;
|
package/lib/use.js
CHANGED
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
} from "./chunk-G2ADBYYC.js";
|
|
4
4
|
|
|
5
5
|
// src/use.ts
|
|
6
|
-
import { ref as ref3 } from "vue";
|
|
6
|
+
import { onUnmounted, ref as ref3 } from "vue";
|
|
7
7
|
import { isFunction } from "rattail";
|
|
8
8
|
|
|
9
9
|
// src/composables/useValues.ts
|
|
@@ -53,12 +53,18 @@ function normalizeValueGetter(valueGetter) {
|
|
|
53
53
|
return isFunction(valueGetter) ? valueGetter() : valueGetter;
|
|
54
54
|
}
|
|
55
55
|
function createUseAxle(options) {
|
|
56
|
-
const {
|
|
56
|
+
const {
|
|
57
|
+
axle,
|
|
58
|
+
onTransform: defaultOnTransform,
|
|
59
|
+
immediate: defaultImmediate = true,
|
|
60
|
+
abortOnUnmount: defaultAbortOnUnmount = true
|
|
61
|
+
} = options;
|
|
57
62
|
const useAxle = (options2) => {
|
|
58
63
|
const {
|
|
59
64
|
url: initialUrlOrGetter,
|
|
60
65
|
method,
|
|
61
66
|
immediate = defaultImmediate,
|
|
67
|
+
abortOnUnmount = defaultAbortOnUnmount,
|
|
62
68
|
value: initialValue,
|
|
63
69
|
resetValue: initialResetValue,
|
|
64
70
|
cloneResetValue: initialCloneResetValue,
|
|
@@ -154,6 +160,11 @@ function createUseAxle(options) {
|
|
|
154
160
|
config: normalizeValueGetter(initialConfigOrGetter)
|
|
155
161
|
});
|
|
156
162
|
}
|
|
163
|
+
if (abortOnUnmount) {
|
|
164
|
+
onUnmounted(() => {
|
|
165
|
+
abort();
|
|
166
|
+
});
|
|
167
|
+
}
|
|
157
168
|
function resetValue(options3 = {}) {
|
|
158
169
|
var _a, _b;
|
|
159
170
|
const cloneResetValue = (_b = (_a = options3.cloneResetValue) != null ? _a : initialCloneResetValue) != null ? _b : false;
|