@ahoo-wang/fetcher-react 2.12.9 → 2.13.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/README.md +67 -0
- package/README.zh-CN.md +67 -0
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/useLatest.d.ts +2 -2
- package/dist/core/useLatest.d.ts.map +1 -1
- package/dist/core/useRefs.d.ts +41 -0
- package/dist/core/useRefs.d.ts.map +1 -0
- package/dist/index.es.js +190 -160
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/package.json +6 -6
package/dist/index.es.js
CHANGED
|
@@ -1,249 +1,279 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
import { useRef as h, useCallback as
|
|
1
|
+
var Q = Object.defineProperty;
|
|
2
|
+
var g = (e, r) => Q(e, "name", { value: r, configurable: !0 });
|
|
3
|
+
import { useRef as h, useCallback as n, useEffect as L, useState as w, useMemo as b, useSyncExternalStore as M } from "react";
|
|
4
4
|
import { nameGenerator as q } from "@ahoo-wang/fetcher-eventbus";
|
|
5
5
|
import { fetcherRegistrar as O, getFetcher as A } from "@ahoo-wang/fetcher";
|
|
6
|
-
function
|
|
7
|
-
const
|
|
8
|
-
return
|
|
9
|
-
|
|
6
|
+
function v() {
|
|
7
|
+
const e = h(!1), r = n(() => e.current, []);
|
|
8
|
+
return L(() => (e.current = !0, () => {
|
|
9
|
+
e.current = !1;
|
|
10
10
|
}), []), r;
|
|
11
11
|
}
|
|
12
|
-
|
|
13
|
-
function
|
|
14
|
-
const r = h(
|
|
15
|
-
return r.current =
|
|
12
|
+
g(v, "useMounted");
|
|
13
|
+
function R(e) {
|
|
14
|
+
const r = h(e);
|
|
15
|
+
return r.current = e, r;
|
|
16
16
|
}
|
|
17
|
-
|
|
18
|
-
var
|
|
19
|
-
function C(
|
|
20
|
-
const [r,
|
|
21
|
-
|
|
17
|
+
g(R, "useLatest");
|
|
18
|
+
var z = /* @__PURE__ */ ((e) => (e.IDLE = "idle", e.LOADING = "loading", e.SUCCESS = "success", e.ERROR = "error", e))(z || {});
|
|
19
|
+
function C(e) {
|
|
20
|
+
const [r, s] = w(
|
|
21
|
+
e?.initialStatus ?? "idle"
|
|
22
22
|
/* IDLE */
|
|
23
|
-
), [
|
|
24
|
-
|
|
23
|
+
), [c, i] = w(void 0), [u, t] = w(void 0), o = v(), f = R(e), l = n(() => {
|
|
24
|
+
o() && (s(
|
|
25
25
|
"loading"
|
|
26
26
|
/* LOADING */
|
|
27
|
-
),
|
|
28
|
-
}, [
|
|
29
|
-
async (
|
|
30
|
-
if (
|
|
31
|
-
|
|
27
|
+
), t(void 0));
|
|
28
|
+
}, [o]), y = n(
|
|
29
|
+
async (d) => {
|
|
30
|
+
if (o()) {
|
|
31
|
+
i(d), s(
|
|
32
32
|
"success"
|
|
33
33
|
/* SUCCESS */
|
|
34
|
-
),
|
|
34
|
+
), t(void 0);
|
|
35
35
|
try {
|
|
36
|
-
await
|
|
36
|
+
await f.current?.onSuccess?.(d);
|
|
37
37
|
} catch (m) {
|
|
38
38
|
console.warn("PromiseState onSuccess callback error:", m);
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
},
|
|
42
|
-
[
|
|
43
|
-
),
|
|
44
|
-
async (
|
|
45
|
-
if (
|
|
46
|
-
|
|
42
|
+
[o, f]
|
|
43
|
+
), a = n(
|
|
44
|
+
async (d) => {
|
|
45
|
+
if (o()) {
|
|
46
|
+
t(d), s(
|
|
47
47
|
"error"
|
|
48
48
|
/* ERROR */
|
|
49
|
-
),
|
|
49
|
+
), i(void 0);
|
|
50
50
|
try {
|
|
51
|
-
await
|
|
51
|
+
await f.current?.onError?.(d);
|
|
52
52
|
} catch (m) {
|
|
53
53
|
console.warn("PromiseState onError callback error:", m);
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
},
|
|
57
|
-
[
|
|
58
|
-
),
|
|
59
|
-
|
|
57
|
+
[o, f]
|
|
58
|
+
), E = n(() => {
|
|
59
|
+
o() && (s(
|
|
60
60
|
"idle"
|
|
61
61
|
/* IDLE */
|
|
62
|
-
),
|
|
63
|
-
}, [
|
|
64
|
-
return
|
|
62
|
+
), t(void 0), i(void 0));
|
|
63
|
+
}, [o]);
|
|
64
|
+
return b(
|
|
65
65
|
() => ({
|
|
66
66
|
status: r,
|
|
67
67
|
loading: r === "loading",
|
|
68
|
-
result:
|
|
68
|
+
result: c,
|
|
69
69
|
error: u,
|
|
70
70
|
setLoading: l,
|
|
71
|
-
setSuccess:
|
|
72
|
-
setError:
|
|
73
|
-
setIdle:
|
|
71
|
+
setSuccess: y,
|
|
72
|
+
setError: a,
|
|
73
|
+
setIdle: E
|
|
74
74
|
}),
|
|
75
|
-
[r,
|
|
75
|
+
[r, c, u, l, y, a, E]
|
|
76
76
|
);
|
|
77
77
|
}
|
|
78
|
-
|
|
79
|
-
function
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
}, []), u =
|
|
83
|
-
|
|
78
|
+
g(C, "usePromiseState");
|
|
79
|
+
function F() {
|
|
80
|
+
const e = h(0), r = n(() => ++e.current, []), s = n(() => e.current, []), c = n((t) => t === e.current, []), i = n(() => {
|
|
81
|
+
e.current++;
|
|
82
|
+
}, []), u = n(() => {
|
|
83
|
+
e.current = 0;
|
|
84
84
|
}, []);
|
|
85
|
-
return
|
|
85
|
+
return b(() => ({
|
|
86
86
|
generate: r,
|
|
87
|
-
current:
|
|
88
|
-
isLatest:
|
|
89
|
-
invalidate:
|
|
87
|
+
current: s,
|
|
88
|
+
isLatest: c,
|
|
89
|
+
invalidate: i,
|
|
90
90
|
reset: u
|
|
91
|
-
}), [r,
|
|
91
|
+
}), [r, s, c, i, u]);
|
|
92
92
|
}
|
|
93
|
-
|
|
94
|
-
function
|
|
95
|
-
const { loading: r, result:
|
|
93
|
+
g(F, "useRequestId");
|
|
94
|
+
function D(e) {
|
|
95
|
+
const { loading: r, result: s, error: c, status: i, setLoading: u, setSuccess: t, setError: o, setIdle: f } = C(e), l = v(), y = F(), a = e?.propagateError, E = n(
|
|
96
96
|
async (m) => {
|
|
97
97
|
if (!l())
|
|
98
98
|
throw new Error("Component is unmounted");
|
|
99
|
-
const
|
|
99
|
+
const p = y.generate();
|
|
100
100
|
u();
|
|
101
101
|
try {
|
|
102
|
-
const
|
|
103
|
-
return l() &&
|
|
104
|
-
} catch (
|
|
105
|
-
if (l() &&
|
|
106
|
-
throw
|
|
107
|
-
return
|
|
102
|
+
const I = await (typeof m == "function" ? m() : m);
|
|
103
|
+
return l() && y.isLatest(p) && await t(I), I;
|
|
104
|
+
} catch (x) {
|
|
105
|
+
if (l() && y.isLatest(p) && await o(x), a)
|
|
106
|
+
throw x;
|
|
107
|
+
return x;
|
|
108
108
|
}
|
|
109
109
|
},
|
|
110
|
-
[u,
|
|
111
|
-
),
|
|
112
|
-
l() &&
|
|
113
|
-
}, [
|
|
114
|
-
return
|
|
110
|
+
[u, t, o, l, y, a]
|
|
111
|
+
), d = n(() => {
|
|
112
|
+
l() && f();
|
|
113
|
+
}, [f, l]);
|
|
114
|
+
return b(
|
|
115
115
|
() => ({
|
|
116
116
|
loading: r,
|
|
117
|
-
result:
|
|
118
|
-
error:
|
|
119
|
-
execute:
|
|
120
|
-
reset:
|
|
121
|
-
status:
|
|
117
|
+
result: s,
|
|
118
|
+
error: c,
|
|
119
|
+
execute: E,
|
|
120
|
+
reset: d,
|
|
121
|
+
status: i
|
|
122
|
+
}),
|
|
123
|
+
[r, s, c, E, d, i]
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
g(D, "useExecutePromise");
|
|
127
|
+
function N() {
|
|
128
|
+
const e = h(/* @__PURE__ */ new Map()), r = n((a) => e.current.get(a), []), s = n(
|
|
129
|
+
(a, E) => e.current.set(a, E),
|
|
130
|
+
[]
|
|
131
|
+
), c = n((a) => e.current.has(a), []), i = n((a) => e.current.delete(a), []), u = n(() => e.current.clear(), []), t = n(() => e.current.keys(), []), o = n(() => e.current.values(), []), f = n(() => e.current.entries(), []), l = n(() => e.current[Symbol.iterator](), []), y = n((a) => (E) => {
|
|
132
|
+
E ? e.current.set(a, E) : e.current.delete(a);
|
|
133
|
+
}, []);
|
|
134
|
+
return L(() => () => {
|
|
135
|
+
e.current.clear();
|
|
136
|
+
}, []), b(
|
|
137
|
+
() => ({
|
|
138
|
+
register: y,
|
|
139
|
+
get: r,
|
|
140
|
+
set: s,
|
|
141
|
+
has: c,
|
|
142
|
+
delete: i,
|
|
143
|
+
clear: u,
|
|
144
|
+
keys: t,
|
|
145
|
+
values: o,
|
|
146
|
+
entries: f,
|
|
147
|
+
get size() {
|
|
148
|
+
return e.current.size;
|
|
149
|
+
},
|
|
150
|
+
[Symbol.iterator]: l
|
|
122
151
|
}),
|
|
123
|
-
[
|
|
152
|
+
[y, r, s, c, i, u, t, o, f, l]
|
|
124
153
|
);
|
|
125
154
|
}
|
|
126
|
-
|
|
127
|
-
function
|
|
128
|
-
const
|
|
129
|
-
(
|
|
155
|
+
g(N, "useRefs");
|
|
156
|
+
function U(e, r) {
|
|
157
|
+
const s = n(
|
|
158
|
+
(t) => e.addListener({
|
|
130
159
|
name: q.generate("useKeyStorage"),
|
|
131
160
|
// Generate unique listener name
|
|
132
|
-
handle:
|
|
161
|
+
handle: t
|
|
133
162
|
// Callback to trigger React re-render on storage changes
|
|
134
163
|
}),
|
|
135
|
-
[
|
|
164
|
+
[e]
|
|
136
165
|
// Recreate subscription only if keyStorage changes
|
|
137
|
-
),
|
|
138
|
-
const
|
|
139
|
-
return
|
|
140
|
-
}, [
|
|
141
|
-
(
|
|
142
|
-
[
|
|
166
|
+
), c = n(() => {
|
|
167
|
+
const t = e.get();
|
|
168
|
+
return t !== null ? t : r ?? null;
|
|
169
|
+
}, [e, r]), i = M(s, c, c), u = n(
|
|
170
|
+
(t) => e.set(t),
|
|
171
|
+
[e]
|
|
143
172
|
// Recreate setter only if keyStorage changes
|
|
144
173
|
);
|
|
145
|
-
return [
|
|
174
|
+
return [i, u];
|
|
146
175
|
}
|
|
147
|
-
|
|
148
|
-
function
|
|
149
|
-
const { fetcher: r = O.default } =
|
|
176
|
+
g(U, "useKeyStorage");
|
|
177
|
+
function V(e) {
|
|
178
|
+
const { fetcher: r = O.default } = e || {}, s = C(e), [c, i] = w(
|
|
150
179
|
void 0
|
|
151
|
-
), u =
|
|
152
|
-
async (
|
|
153
|
-
|
|
154
|
-
const
|
|
155
|
-
|
|
180
|
+
), u = v(), t = h(void 0), o = F(), f = R(e), l = A(r), y = n(
|
|
181
|
+
async (a) => {
|
|
182
|
+
t.current && t.current.abort(), t.current = a.abortController ?? new AbortController(), a.abortController = t.current;
|
|
183
|
+
const E = o.generate();
|
|
184
|
+
s.setLoading();
|
|
156
185
|
try {
|
|
157
|
-
const
|
|
158
|
-
|
|
159
|
-
|
|
186
|
+
const d = await l.exchange(
|
|
187
|
+
a,
|
|
188
|
+
f.current
|
|
160
189
|
);
|
|
161
|
-
u() &&
|
|
162
|
-
const m = await
|
|
163
|
-
u() &&
|
|
164
|
-
} catch (
|
|
165
|
-
if (
|
|
166
|
-
u() &&
|
|
190
|
+
u() && o.isLatest(E) && i(d);
|
|
191
|
+
const m = await d.extractResult();
|
|
192
|
+
u() && o.isLatest(E) && await s.setSuccess(m);
|
|
193
|
+
} catch (d) {
|
|
194
|
+
if (d instanceof Error && d.name === "AbortError") {
|
|
195
|
+
u() && s.setIdle();
|
|
167
196
|
return;
|
|
168
197
|
}
|
|
169
|
-
u() &&
|
|
198
|
+
u() && o.isLatest(E) && await s.setError(d);
|
|
170
199
|
} finally {
|
|
171
|
-
|
|
200
|
+
t.current === a.abortController && (t.current = void 0);
|
|
172
201
|
}
|
|
173
202
|
},
|
|
174
|
-
[l, u,
|
|
203
|
+
[l, u, f, s, o]
|
|
175
204
|
);
|
|
176
|
-
return
|
|
177
|
-
|
|
178
|
-
}, []),
|
|
205
|
+
return L(() => () => {
|
|
206
|
+
t.current?.abort(), t.current = void 0;
|
|
207
|
+
}, []), b(
|
|
179
208
|
() => ({
|
|
180
|
-
...
|
|
181
|
-
exchange:
|
|
182
|
-
execute:
|
|
209
|
+
...s,
|
|
210
|
+
exchange: c,
|
|
211
|
+
execute: y
|
|
183
212
|
}),
|
|
184
|
-
[
|
|
213
|
+
[s, c, y]
|
|
185
214
|
);
|
|
186
215
|
}
|
|
187
|
-
|
|
188
|
-
function
|
|
189
|
-
const r =
|
|
190
|
-
|
|
216
|
+
g(V, "useFetcher");
|
|
217
|
+
function S(e) {
|
|
218
|
+
const r = R(e), s = D(r.current), c = h(e.initialQuery), i = n(async () => r.current.execute(
|
|
219
|
+
c.current,
|
|
191
220
|
r.current.attributes
|
|
192
|
-
), [
|
|
221
|
+
), [c, r]), { execute: u } = s, t = n(() => u(i), [u, i]), o = n(() => c.current, [c]), f = n(
|
|
193
222
|
(l) => {
|
|
194
|
-
|
|
223
|
+
c.current = l, r.current.autoExecute && t();
|
|
195
224
|
},
|
|
196
|
-
[
|
|
225
|
+
[c, r, t]
|
|
197
226
|
);
|
|
198
|
-
return
|
|
199
|
-
r.current.autoExecute &&
|
|
200
|
-
}, [r,
|
|
227
|
+
return L(() => {
|
|
228
|
+
r.current.autoExecute && t();
|
|
229
|
+
}, [r, t]), b(
|
|
201
230
|
() => ({
|
|
202
|
-
...
|
|
203
|
-
execute:
|
|
204
|
-
getQuery:
|
|
205
|
-
setQuery:
|
|
231
|
+
...s,
|
|
232
|
+
execute: t,
|
|
233
|
+
getQuery: o,
|
|
234
|
+
setQuery: f
|
|
206
235
|
}),
|
|
207
|
-
[
|
|
236
|
+
[s, t, o, f]
|
|
208
237
|
);
|
|
209
238
|
}
|
|
210
|
-
|
|
211
|
-
function
|
|
212
|
-
return
|
|
239
|
+
g(S, "useQuery");
|
|
240
|
+
function j(e) {
|
|
241
|
+
return S(e);
|
|
213
242
|
}
|
|
214
|
-
|
|
215
|
-
function
|
|
216
|
-
return
|
|
243
|
+
g(j, "usePagedQuery");
|
|
244
|
+
function B(e) {
|
|
245
|
+
return S(e);
|
|
217
246
|
}
|
|
218
|
-
|
|
219
|
-
function
|
|
220
|
-
return
|
|
247
|
+
g(B, "useSingleQuery");
|
|
248
|
+
function H(e) {
|
|
249
|
+
return S(e);
|
|
221
250
|
}
|
|
222
|
-
|
|
223
|
-
function
|
|
224
|
-
return
|
|
251
|
+
g(H, "useCountQuery");
|
|
252
|
+
function J(e) {
|
|
253
|
+
return S(e);
|
|
225
254
|
}
|
|
226
|
-
|
|
227
|
-
function
|
|
228
|
-
return
|
|
229
|
-
|
|
255
|
+
g(J, "useListQuery");
|
|
256
|
+
function T(e) {
|
|
257
|
+
return S(
|
|
258
|
+
e
|
|
230
259
|
);
|
|
231
260
|
}
|
|
232
|
-
|
|
261
|
+
g(T, "useListStreamQuery");
|
|
233
262
|
export {
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
263
|
+
z as PromiseStatus,
|
|
264
|
+
H as useCountQuery,
|
|
265
|
+
D as useExecutePromise,
|
|
266
|
+
V as useFetcher,
|
|
267
|
+
U as useKeyStorage,
|
|
268
|
+
R as useLatest,
|
|
269
|
+
J as useListQuery,
|
|
270
|
+
T as useListStreamQuery,
|
|
271
|
+
v as useMounted,
|
|
272
|
+
j as usePagedQuery,
|
|
244
273
|
C as usePromiseState,
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
274
|
+
S as useQuery,
|
|
275
|
+
N as useRefs,
|
|
276
|
+
F as useRequestId,
|
|
277
|
+
B as useSingleQuery
|
|
248
278
|
};
|
|
249
279
|
//# sourceMappingURL=index.es.js.map
|