@lemon-fe/hooks 1.4.15 → 1.4.27-alpha.0
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/config.d.ts +2 -0
- package/es/use-request/index.d.ts +4 -0
- package/es/use-request/index.js +26 -13
- package/package.json +2 -2
package/es/config.d.ts
CHANGED
|
@@ -8,6 +8,8 @@ export interface HooksOpts<ToastReturnType = any> {
|
|
|
8
8
|
setPrimaryColor: (val: string) => void;
|
|
9
9
|
/** 默认throttle时间,便于移动端使用 */
|
|
10
10
|
requestThrottleInterval: number;
|
|
11
|
+
/** request lock 防止 useRequest 重复调用 */
|
|
12
|
+
requestLock?: boolean;
|
|
11
13
|
}
|
|
12
14
|
export declare const hooksOpts: HooksOpts;
|
|
13
15
|
/**
|
package/es/use-request/index.js
CHANGED
|
@@ -38,7 +38,9 @@ export default function useRequest(request) {
|
|
|
38
38
|
defaultData = _options$defaultData === void 0 ? null : _options$defaultData,
|
|
39
39
|
_options$refreshDeps = options.refreshDeps,
|
|
40
40
|
refreshDeps = _options$refreshDeps === void 0 ? [] : _options$refreshDeps,
|
|
41
|
-
onFinally = options.onFinally
|
|
41
|
+
onFinally = options.onFinally,
|
|
42
|
+
_options$lock = options.lock,
|
|
43
|
+
lock = _options$lock === void 0 ? hooksOpts.requestLock : _options$lock;
|
|
42
44
|
var _useState = useState(false),
|
|
43
45
|
_useState2 = _slicedToArray(_useState, 2),
|
|
44
46
|
loading = _useState2[0],
|
|
@@ -50,6 +52,7 @@ export default function useRequest(request) {
|
|
|
50
52
|
var mounted = useRef(false);
|
|
51
53
|
var toastRef = useRef(null);
|
|
52
54
|
var fetchId = useRef(0);
|
|
55
|
+
var lockRef = useRef(false);
|
|
53
56
|
var start = useCallback(function () {
|
|
54
57
|
if (toast && !toastRef.current) {
|
|
55
58
|
toastRef.current = hooksOpts.showToast() || true;
|
|
@@ -86,16 +89,25 @@ export default function useRequest(request) {
|
|
|
86
89
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
87
90
|
while (1) switch (_context.prev = _context.next) {
|
|
88
91
|
case 0:
|
|
92
|
+
if (!lockRef.current) {
|
|
93
|
+
_context.next = 2;
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
return _context.abrupt("return");
|
|
97
|
+
case 2:
|
|
98
|
+
if (lock) {
|
|
99
|
+
lockRef.current = true;
|
|
100
|
+
}
|
|
89
101
|
fetchId.current += 1;
|
|
90
102
|
start();
|
|
91
103
|
id = fetchId.current;
|
|
92
104
|
for (_len = _args.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
93
105
|
args[_key] = _args[_key];
|
|
94
106
|
}
|
|
95
|
-
_context.prev =
|
|
96
|
-
_context.next =
|
|
107
|
+
_context.prev = 7;
|
|
108
|
+
_context.next = 10;
|
|
97
109
|
return request.apply(void 0, args);
|
|
98
|
-
case
|
|
110
|
+
case 10:
|
|
99
111
|
_res = _context.sent;
|
|
100
112
|
if (mounted.current && id === fetchId.current) {
|
|
101
113
|
end();
|
|
@@ -106,11 +118,11 @@ export default function useRequest(request) {
|
|
|
106
118
|
} else if (!mounted.current) {
|
|
107
119
|
end();
|
|
108
120
|
}
|
|
109
|
-
_context.next =
|
|
121
|
+
_context.next = 18;
|
|
110
122
|
break;
|
|
111
|
-
case
|
|
112
|
-
_context.prev =
|
|
113
|
-
_context.t0 = _context["catch"](
|
|
123
|
+
case 14:
|
|
124
|
+
_context.prev = 14;
|
|
125
|
+
_context.t0 = _context["catch"](7);
|
|
114
126
|
end();
|
|
115
127
|
if (onError) {
|
|
116
128
|
onError(_context.t0, args, function () {
|
|
@@ -119,15 +131,16 @@ export default function useRequest(request) {
|
|
|
119
131
|
} else {
|
|
120
132
|
hooksOpts.showError(_context.t0);
|
|
121
133
|
}
|
|
122
|
-
case 15:
|
|
123
|
-
_context.prev = 15;
|
|
124
|
-
onFinally === null || onFinally === void 0 || onFinally();
|
|
125
|
-
return _context.finish(15);
|
|
126
134
|
case 18:
|
|
135
|
+
_context.prev = 18;
|
|
136
|
+
onFinally === null || onFinally === void 0 || onFinally();
|
|
137
|
+
lockRef.current = false;
|
|
138
|
+
return _context.finish(18);
|
|
139
|
+
case 22:
|
|
127
140
|
case "end":
|
|
128
141
|
return _context.stop();
|
|
129
142
|
}
|
|
130
|
-
}, _callee, null, [[
|
|
143
|
+
}, _callee, null, [[7, 14, 18, 22]]);
|
|
131
144
|
})));
|
|
132
145
|
var formatedRun = useMemo(function () {
|
|
133
146
|
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.27-alpha.0",
|
|
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": "c5d28b728f3a559fd51e738b5c490323e6551786"
|
|
34
34
|
}
|