@varlet/axle 0.2.12 → 0.2.14
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/index.d.ts +2 -2
- package/es/index.js +2 -2
- package/es/use.d.ts +1 -0
- package/es/use.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -286,6 +286,8 @@ const axle = createAxle(/** @see https://axios-http.com **/)
|
|
|
286
286
|
|
|
287
287
|
const useAxle = createUseAxle({
|
|
288
288
|
axle,
|
|
289
|
+
// Optional value: Default immediate of the useAxle
|
|
290
|
+
immediate: true,
|
|
289
291
|
// Optional value: Default onTransform of the useAxle
|
|
290
292
|
onTransform: (response) => response,
|
|
291
293
|
})
|
package/README.zh-CN.md
CHANGED
package/es/index.d.ts
CHANGED
|
@@ -55,8 +55,8 @@ interface ResponseRetryInterceptorOptions {
|
|
|
55
55
|
declare function responseRetryInterceptor(options: ResponseRetryInterceptorOptions): ResponseInterceptor;
|
|
56
56
|
|
|
57
57
|
interface ResponseStatusInterceptorOptions {
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
validStatusHandler?: Record<number | string, (response: AxiosResponse<any, any>) => any>;
|
|
59
|
+
invalidStatusHandler?: Record<number | string, (error: any) => any>;
|
|
60
60
|
include?: string[];
|
|
61
61
|
exclude?: string[];
|
|
62
62
|
axiosInterceptorOptions?: AxiosInterceptorOptions;
|
package/es/index.js
CHANGED
|
@@ -296,7 +296,7 @@ function responseStatusInterceptor(options) {
|
|
|
296
296
|
if (!matcher((_a = response.config.method) != null ? _a : "", (_b = response.config.url) != null ? _b : "")) {
|
|
297
297
|
return response;
|
|
298
298
|
}
|
|
299
|
-
const handler = ((_c = options.
|
|
299
|
+
const handler = ((_c = options.validStatusHandler) != null ? _c : {})[response.status];
|
|
300
300
|
if (!handler) {
|
|
301
301
|
return response;
|
|
302
302
|
}
|
|
@@ -309,7 +309,7 @@ function responseStatusInterceptor(options) {
|
|
|
309
309
|
if (!matcher((_a = error.config.method) != null ? _a : "", (_b = error.config.url) != null ? _b : "")) {
|
|
310
310
|
return Promise.reject(error);
|
|
311
311
|
}
|
|
312
|
-
const handler = ((_c = options.
|
|
312
|
+
const handler = ((_c = options.invalidStatusHandler) != null ? _c : {})[error.response.status];
|
|
313
313
|
if (!handler) {
|
|
314
314
|
return Promise.reject(error);
|
|
315
315
|
}
|
package/es/use.d.ts
CHANGED
|
@@ -49,6 +49,7 @@ type UseAxleInstance<V, R, P> = [
|
|
|
49
49
|
];
|
|
50
50
|
interface CreateUseAxleOptions {
|
|
51
51
|
axle: AxleInstance;
|
|
52
|
+
immediate?: boolean;
|
|
52
53
|
onTransform?(response: any, refs: any): any;
|
|
53
54
|
}
|
|
54
55
|
declare function createUseAxle(options: CreateUseAxleOptions): <V = any, R = any, P = Record<string, any>>(options: UseAxleOptions<V, R, P>) => UseAxleInstance<V, R, P>;
|
package/es/use.js
CHANGED
|
@@ -50,12 +50,12 @@ function useAverageProgress(...progressCollection) {
|
|
|
50
50
|
|
|
51
51
|
// src/use.ts
|
|
52
52
|
function createUseAxle(options) {
|
|
53
|
-
const { axle, onTransform: defaultOnTransform } = options;
|
|
53
|
+
const { axle, onTransform: defaultOnTransform, immediate: defaultImmediate = false } = options;
|
|
54
54
|
const useAxle = (options2) => {
|
|
55
55
|
const {
|
|
56
56
|
url,
|
|
57
57
|
method,
|
|
58
|
-
immediate,
|
|
58
|
+
immediate = defaultImmediate,
|
|
59
59
|
value: initialValue,
|
|
60
60
|
resetValue: initialResetValue,
|
|
61
61
|
params: initialParamsOrGetter,
|