Skip to content

Commit

Permalink
feat(deprecated): deprecate enableDownload and enableUpload in me…
Browse files Browse the repository at this point in the history
…thod config, these are auto now
  • Loading branch information
JOU-amjs committed Apr 18, 2024
1 parent 40a2b6b commit 65c64b8
Show file tree
Hide file tree
Showing 43 changed files with 527 additions and 536 deletions.
186 changes: 68 additions & 118 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
"rimraf": "2.6.2",
"rollup": "^2.74.1",
"rollup-plugin-terser": "^7.0.2",
"rollup-plugin-typescript2": "^0.31.2",
"rollup-plugin-typescript2": "^0.36.0",
"semantic-release": "^21.0.1",
"svelte": "^3.49.0",
"svelte-jester": "^2.3.2",
Expand Down
37 changes: 0 additions & 37 deletions src/Hook.ts

This file was deleted.

21 changes: 17 additions & 4 deletions src/Method.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import { AlovaMethodConfig, MethodRequestConfig, MethodType, ProgressHandler, RequestBody } from '~/typings';
import Alova from './Alova';
import {
AbortFunction,
AlovaMethodConfig,
MethodRequestConfig,
MethodType,
ProgressHandler,
RequestBody
} from '~/typings';
import { Alova } from './alova';
import sendRequest from './functions/sendRequest';
import {
getConfig,
Expand Down Expand Up @@ -36,6 +43,12 @@ export const typePut = 'PUT';
export const typePatch = 'PATCH';
export const typeDelete = 'DELETE';
export const typeOptions = 'OPTIONS';

const abortRequest: AbortFunction = () => {
abortRequest.a();
};
abortRequest.a = noop;

export default class Method<S = any, E = any, R = any, T = any, RC = any, RE = any, RH = any> {
public type: MethodType;
public baseURL: string;
Expand All @@ -52,7 +65,7 @@ export default class Method<S = any, E = any, R = any, T = any, RC = any, RE = a
/**
* 请求中断函数,每次请求都会更新这个函数
*/
public abort = noop;
public abort = abortRequest;
public fromCache: boolean | undefined = undefinedValue;
constructor(
type: MethodType,
Expand Down Expand Up @@ -142,7 +155,7 @@ export default class Method<S = any, E = any, R = any, T = any, RC = any, RE = a
len(instance.uhs) > 0 && onUpload((total, loaded) => forEach(instance.uhs, handler => handler({ total, loaded })));

// 每次请求时将中断函数绑定给method实例,使用者也可通过methodInstance.abort()来中断当前请求
instance.abort = abort;
instance.abort.a = abort;
instance.fromCache = undefinedValue;
return promiseThen(response(), r => {
instance.fromCache = fromCache();
Expand Down

0 comments on commit 65c64b8

Please sign in to comment.