@lemon-fe/hooks 1.4.0 → 1.4.14-alpha.1
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/es/use-request/index.d.ts +11 -3
- package/es/use-request/index.js +26 -13
- package/package.json +2 -2
|
@@ -12,14 +12,22 @@ export default function useRequest<T extends (...args: any[]) => Promise<any> |
|
|
|
12
12
|
onLoading?: (loading: boolean) => void;
|
|
13
13
|
/**
|
|
14
14
|
* 成功回调
|
|
15
|
+
* @param res request返回的数据
|
|
16
|
+
* @param params request的参数
|
|
15
17
|
*/
|
|
16
|
-
onSuccess?: (res: K) => void;
|
|
18
|
+
onSuccess?: (res: K, params: Parameters<T>) => void;
|
|
17
19
|
/**
|
|
18
20
|
* 错误回调
|
|
19
|
-
* @param
|
|
21
|
+
* @param err 异常,抛出异常的时候务必是Error的实例
|
|
22
|
+
* @param params request的参数
|
|
23
|
+
* @param showError 调用全局的错误信息提示
|
|
20
24
|
* @returns
|
|
21
25
|
*/
|
|
22
|
-
onError?: (err: Error) => void;
|
|
26
|
+
onError?: (err: Error, params: Parameters<T>, showError: () => void) => void;
|
|
27
|
+
/**
|
|
28
|
+
* 最终回调
|
|
29
|
+
*/
|
|
30
|
+
onFinally?: () => void;
|
|
23
31
|
/**
|
|
24
32
|
* 节流模式的时间
|
|
25
33
|
*/
|
package/es/use-request/index.js
CHANGED
|
@@ -37,7 +37,8 @@ export default function useRequest(request) {
|
|
|
37
37
|
_options$defaultData = options.defaultData,
|
|
38
38
|
defaultData = _options$defaultData === void 0 ? null : _options$defaultData,
|
|
39
39
|
_options$refreshDeps = options.refreshDeps,
|
|
40
|
-
refreshDeps = _options$refreshDeps === void 0 ? [] : _options$refreshDeps
|
|
40
|
+
refreshDeps = _options$refreshDeps === void 0 ? [] : _options$refreshDeps,
|
|
41
|
+
onFinally = options.onFinally;
|
|
41
42
|
var _useState = useState(false),
|
|
42
43
|
_useState2 = _slicedToArray(_useState, 2),
|
|
43
44
|
loading = _useState2[0],
|
|
@@ -77,6 +78,9 @@ export default function useRequest(request) {
|
|
|
77
78
|
}, []);
|
|
78
79
|
var runRef = useLastestRef( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
79
80
|
var id,
|
|
81
|
+
_len,
|
|
82
|
+
args,
|
|
83
|
+
_key,
|
|
80
84
|
_res,
|
|
81
85
|
_args = arguments;
|
|
82
86
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
@@ -85,36 +89,45 @@ export default function useRequest(request) {
|
|
|
85
89
|
fetchId.current += 1;
|
|
86
90
|
start();
|
|
87
91
|
id = fetchId.current;
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
+
for (_len = _args.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
93
|
+
args[_key] = _args[_key];
|
|
94
|
+
}
|
|
95
|
+
_context.prev = 4;
|
|
96
|
+
_context.next = 7;
|
|
97
|
+
return request.apply(void 0, args);
|
|
98
|
+
case 7:
|
|
92
99
|
_res = _context.sent;
|
|
93
100
|
if (mounted.current && id === fetchId.current) {
|
|
94
101
|
end();
|
|
95
|
-
onSuccess === null || onSuccess === void 0 || onSuccess(_res);
|
|
102
|
+
onSuccess === null || onSuccess === void 0 || onSuccess(_res, args);
|
|
96
103
|
if (!manual) {
|
|
97
104
|
setData(_res);
|
|
98
105
|
}
|
|
99
106
|
} else if (!mounted.current) {
|
|
100
107
|
end();
|
|
101
108
|
}
|
|
102
|
-
_context.next =
|
|
109
|
+
_context.next = 15;
|
|
103
110
|
break;
|
|
104
|
-
case
|
|
105
|
-
_context.prev =
|
|
106
|
-
_context.t0 = _context["catch"](
|
|
111
|
+
case 11:
|
|
112
|
+
_context.prev = 11;
|
|
113
|
+
_context.t0 = _context["catch"](4);
|
|
107
114
|
end();
|
|
108
115
|
if (onError) {
|
|
109
|
-
onError(_context.t0)
|
|
116
|
+
onError(_context.t0, args, function () {
|
|
117
|
+
hooksOpts.showError(_context.t0);
|
|
118
|
+
});
|
|
110
119
|
} else {
|
|
111
120
|
hooksOpts.showError(_context.t0);
|
|
112
121
|
}
|
|
113
|
-
case
|
|
122
|
+
case 15:
|
|
123
|
+
_context.prev = 15;
|
|
124
|
+
onFinally === null || onFinally === void 0 || onFinally();
|
|
125
|
+
return _context.finish(15);
|
|
126
|
+
case 18:
|
|
114
127
|
case "end":
|
|
115
128
|
return _context.stop();
|
|
116
129
|
}
|
|
117
|
-
}, _callee, null, [[
|
|
130
|
+
}, _callee, null, [[4, 11, 15, 18]]);
|
|
118
131
|
})));
|
|
119
132
|
var formatedRun = useMemo(function () {
|
|
120
133
|
var cb = function cb() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lemon-fe/hooks",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.14-alpha.1",
|
|
4
4
|
"description": "> TODO: description",
|
|
5
5
|
"author": "lusj",
|
|
6
6
|
"homepage": "",
|
|
@@ -30,5 +30,5 @@
|
|
|
30
30
|
"antd": "^4.24.8",
|
|
31
31
|
"react": "^17.0.2"
|
|
32
32
|
},
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "57033c6a96c4e184fb28b629aa7318525fd6bbd3"
|
|
34
34
|
}
|