@varlet/axle 0.2.2 → 0.2.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 +2 -0
- package/README.zh-CN.md +2 -0
- package/es/use.d.ts +2 -0
- package/es/use.js +7 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -218,6 +218,8 @@ const [users, getUsers, { loading, error, uploadProgress, downloadProgress, abor
|
|
|
218
218
|
immediate: true,
|
|
219
219
|
// The number of retries after a failed request, defaults 0
|
|
220
220
|
retry: 3,
|
|
221
|
+
// Whether the value needs to be reset before requesting, defaults false
|
|
222
|
+
resetValue: true,
|
|
221
223
|
// Request params, defaults {}
|
|
222
224
|
// When params is an object, it will be carried when sending the first request (immediate)
|
|
223
225
|
// When params is a function, it will be carried every time a request is sent.
|
package/README.zh-CN.md
CHANGED
|
@@ -218,6 +218,8 @@ const [users, getUsers, { loading, error, uploadProgress, downloadProgress, abor
|
|
|
218
218
|
immediate: true,
|
|
219
219
|
// 错误重试次数, 默认值: 0
|
|
220
220
|
retry: 3,
|
|
221
|
+
// 请求前是否需要重置 value, 默认值: false
|
|
222
|
+
resetValue: true,
|
|
221
223
|
// 请求参数, 默认值: {}
|
|
222
224
|
// 当参数是一个对象时,发送第一个请求(immediate)时将携带它
|
|
223
225
|
// 当参数是一个函数时,每次发送请求时都会携带它。
|
package/es/use.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export interface RunOptions<P> {
|
|
|
4
4
|
url?: string;
|
|
5
5
|
params?: P;
|
|
6
6
|
config?: AxleRequestConfig;
|
|
7
|
+
resetValue?: boolean;
|
|
7
8
|
_retryCount?: number;
|
|
8
9
|
}
|
|
9
10
|
export type Run<R, P> = (options?: RunOptions<P>) => Promise<R>;
|
|
@@ -20,6 +21,7 @@ export interface UseAxleOptions<V = any, R = any, P = Record<string, any>> {
|
|
|
20
21
|
value?: V;
|
|
21
22
|
params?: P | (() => P);
|
|
22
23
|
retry?: number;
|
|
24
|
+
resetValue?: boolean;
|
|
23
25
|
config?: AxleRequestConfig;
|
|
24
26
|
immediate?: boolean;
|
|
25
27
|
onBefore?(refs: UseAxleRefs<V>): void;
|
package/es/use.js
CHANGED
|
@@ -4,7 +4,7 @@ export function createUseAxle(options) {
|
|
|
4
4
|
const { axle, onTransform: defaultOnTransform } = options;
|
|
5
5
|
const useAxle = (options) => {
|
|
6
6
|
var _a;
|
|
7
|
-
const { url, method, immediate, value: initialValue, params: initialParamsOrGetter, config: initialConfig, retry = 0, onBefore = () => { }, onAfter = () => { }, onTransform = (_a = defaultOnTransform) !== null && _a !== void 0 ? _a : ((response) => response), onSuccess = () => { }, onError = () => { }, } = options;
|
|
7
|
+
const { url, method, immediate, value: initialValue, resetValue: initialResetValue, params: initialParamsOrGetter, config: initialConfig, retry = 0, onBefore = () => { }, onAfter = () => { }, onTransform = (_a = defaultOnTransform) !== null && _a !== void 0 ? _a : ((response) => response), onSuccess = () => { }, onError = () => { }, } = options;
|
|
8
8
|
const initialUrl = url;
|
|
9
9
|
const value = ref(initialValue);
|
|
10
10
|
const loading = ref(false);
|
|
@@ -21,13 +21,17 @@ export function createUseAxle(options) {
|
|
|
21
21
|
};
|
|
22
22
|
let controller = new AbortController();
|
|
23
23
|
const run = async (options = {}) => {
|
|
24
|
-
var _a;
|
|
24
|
+
var _a, _b, _c;
|
|
25
25
|
if (controller.signal.aborted) {
|
|
26
26
|
controller = new AbortController();
|
|
27
27
|
}
|
|
28
|
+
const resetValue = (_b = (_a = options.resetValue) !== null && _a !== void 0 ? _a : initialResetValue) !== null && _b !== void 0 ? _b : false;
|
|
29
|
+
if (resetValue === true) {
|
|
30
|
+
value.value = initialValue;
|
|
31
|
+
}
|
|
28
32
|
uploadProgress.value = 0;
|
|
29
33
|
downloadProgress.value = 0;
|
|
30
|
-
const url = (
|
|
34
|
+
const url = (_c = options.url) !== null && _c !== void 0 ? _c : initialUrl;
|
|
31
35
|
onBefore(refs);
|
|
32
36
|
loading.value = true;
|
|
33
37
|
try {
|