@depup/reduxjs__toolkit 2.12.0-depup.28 → 2.13.0-depup.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/README.md +4 -4
- package/changes.json +3 -3
- package/dist/cjs/redux-toolkit.development.cjs +1755 -2247
- package/dist/cjs/redux-toolkit.development.cjs.map +1 -1
- package/dist/cjs/redux-toolkit.production.min.cjs +1 -2
- package/dist/cjs/redux-toolkit.production.min.cjs.map +1 -1
- package/dist/index.d.mts +1496 -1525
- package/dist/index.d.ts +1496 -1525
- package/dist/query/cjs/rtk-query.development.cjs +2059 -2990
- package/dist/query/cjs/rtk-query.development.cjs.map +1 -1
- package/dist/query/cjs/rtk-query.production.min.cjs +1 -1
- package/dist/query/cjs/rtk-query.production.min.cjs.map +1 -1
- package/dist/query/index.d.mts +2300 -2308
- package/dist/query/index.d.ts +2300 -2308
- package/dist/query/react/cjs/rtk-query-react.development.cjs +609 -714
- package/dist/query/react/cjs/rtk-query-react.development.cjs.map +1 -1
- package/dist/query/react/cjs/rtk-query-react.production.min.cjs +1 -1
- package/dist/query/react/cjs/rtk-query-react.production.min.cjs.map +1 -1
- package/dist/query/react/index.d.mts +516 -523
- package/dist/query/react/index.d.ts +516 -523
- package/dist/query/react/rtk-query-react.browser.mjs +1 -1
- package/dist/query/react/rtk-query-react.browser.mjs.map +1 -1
- package/dist/query/react/rtk-query-react.legacy-esm.js +672 -714
- package/dist/query/react/rtk-query-react.legacy-esm.js.map +1 -1
- package/dist/query/react/rtk-query-react.modern.mjs +586 -679
- package/dist/query/react/rtk-query-react.modern.mjs.map +1 -1
- package/dist/query/rtk-query.browser.mjs +1 -1
- package/dist/query/rtk-query.browser.mjs.map +1 -1
- package/dist/query/rtk-query.legacy-esm.js +2175 -3014
- package/dist/query/rtk-query.legacy-esm.js.map +1 -1
- package/dist/query/rtk-query.modern.mjs +2052 -2949
- package/dist/query/rtk-query.modern.mjs.map +1 -1
- package/dist/react/cjs/redux-toolkit-react.development.cjs +30 -51
- package/dist/react/cjs/redux-toolkit-react.development.cjs.map +1 -1
- package/dist/react/cjs/redux-toolkit-react.production.min.cjs +1 -1
- package/dist/react/cjs/redux-toolkit-react.production.min.cjs.map +1 -1
- package/dist/react/index.d.mts +12 -15
- package/dist/react/index.d.ts +12 -15
- package/dist/react/redux-toolkit-react.browser.mjs +1 -1
- package/dist/react/redux-toolkit-react.browser.mjs.map +1 -1
- package/dist/react/redux-toolkit-react.legacy-esm.js +83 -44
- package/dist/react/redux-toolkit-react.legacy-esm.js.map +1 -1
- package/dist/react/redux-toolkit-react.modern.mjs +23 -25
- package/dist/react/redux-toolkit-react.modern.mjs.map +1 -1
- package/dist/redux-toolkit.browser.mjs +1 -2
- package/dist/redux-toolkit.browser.mjs.map +1 -1
- package/dist/redux-toolkit.legacy-esm.js +1748 -2201
- package/dist/redux-toolkit.legacy-esm.js.map +1 -1
- package/dist/redux-toolkit.modern.mjs +1670 -2171
- package/dist/redux-toolkit.modern.mjs.map +1 -1
- package/package.json +17 -33
- package/skills/build-modern-redux-apps/modern-redux/SKILL.md +23 -14
- package/skills/build-modern-redux-apps/modern-redux/references/store-lifetime.md +6 -6
- package/skills/build-modern-redux-apps/redux-dataflow/SKILL.md +13 -10
- package/skills/evolve-and-diagnose-redux-apps/debug-redux-toolkit-apps/SKILL.md +6 -6
- package/skills/evolve-and-diagnose-redux-apps/migrate-to-modern-redux/SKILL.md +7 -8
- package/skills/manage-server-data/adopt-rtk-query/SKILL.md +13 -11
- package/skills/model-redux-state/build-slices-and-selectors/SKILL.md +26 -14
- package/skills/model-redux-state/design-state-ownership/SKILL.md +11 -12
- package/skills/model-redux-state/design-state-ownership/references/state-ownership.md +6 -6
- package/skills/orchestrate-side-effects/handle-side-effects/SKILL.md +27 -23
- package/skills/orchestrate-side-effects/handle-side-effects/references/listener-workflows.md +4 -4
- package/src/autoBatchEnhancer.ts +5 -3
- package/src/combineSlices.ts +5 -5
- package/src/createAction.ts +11 -6
- package/src/createAsyncThunk.ts +14 -2
- package/src/createReducer.ts +1 -1
- package/src/createSlice.ts +9 -4
- package/src/dynamicMiddleware/index.ts +21 -5
- package/src/entities/models.ts +2 -1
- package/src/entities/sorted_state_adapter.ts +35 -24
- package/src/entities/unsorted_state_adapter.ts +1 -1
- package/src/immutableStateInvariantMiddleware.ts +34 -5
- package/src/listenerMiddleware/types.ts +10 -10
- package/src/mapBuilders.ts +2 -5
- package/src/matchers.ts +7 -1
- package/src/query/core/apiState.ts +1 -1
- package/src/query/core/buildInitiate.ts +19 -15
- package/src/query/core/buildMiddleware/cacheLifecycle.ts +3 -1
- package/src/query/core/buildMiddleware/index.ts +1 -1
- package/src/query/core/buildMiddleware/invalidationByTags.ts +4 -1
- package/src/query/core/buildMiddleware/polling.ts +12 -3
- package/src/query/core/buildMiddleware/types.ts +5 -2
- package/src/query/core/buildSlice.ts +2 -2
- package/src/query/core/buildThunks.ts +19 -0
- package/src/query/core/module.ts +9 -3
- package/src/query/createApi.ts +4 -1
- package/src/query/endpointDefinitions.ts +15 -9
- package/src/query/fetchBaseQuery.ts +1 -1
- package/src/query/react/buildHooks.ts +54 -51
- package/src/query/react/namedHooks.ts +28 -24
- package/src/query/utils/isAbsoluteUrl.ts +8 -3
- package/src/serializableStateInvariantMiddleware.ts +1 -1
|
@@ -1,748 +1,643 @@
|
|
|
1
|
-
"
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region \0rolldown/runtime.js
|
|
2
3
|
var __create = Object.create;
|
|
3
4
|
var __defProp = Object.defineProperty;
|
|
4
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
7
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
8
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
9
|
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
13
|
+
get: ((k) => from[k]).bind(null, key),
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
19
18
|
};
|
|
20
|
-
var
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
)
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
var react_exports = {};
|
|
33
|
-
__export(react_exports, {
|
|
34
|
-
ApiProvider: () => ApiProvider,
|
|
35
|
-
UNINITIALIZED_VALUE: () => UNINITIALIZED_VALUE,
|
|
36
|
-
createApi: () => createApi,
|
|
37
|
-
reactHooksModule: () => reactHooksModule,
|
|
38
|
-
reactHooksModuleName: () => reactHooksModuleName
|
|
39
|
-
});
|
|
40
|
-
module.exports = __toCommonJS(react_exports);
|
|
41
|
-
|
|
42
|
-
// src/query/react/rtkqImports.ts
|
|
43
|
-
var import_query = require("@reduxjs/toolkit/query");
|
|
44
|
-
|
|
45
|
-
// src/query/react/module.ts
|
|
46
|
-
var import_toolkit2 = require("@reduxjs/toolkit");
|
|
47
|
-
var import_react_redux2 = require("react-redux");
|
|
48
|
-
var import_reselect = require("reselect");
|
|
49
|
-
|
|
50
|
-
// src/query/utils/capitalize.ts
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
20
|
+
value: mod,
|
|
21
|
+
enumerable: true
|
|
22
|
+
}) : target, mod));
|
|
23
|
+
//#endregion
|
|
24
|
+
let _reduxjs_toolkit = require("@reduxjs/toolkit");
|
|
25
|
+
let react_redux = require("react-redux");
|
|
26
|
+
let reselect = require("reselect");
|
|
27
|
+
let react = require("react");
|
|
28
|
+
react = __toESM(react);
|
|
29
|
+
let _reduxjs_toolkit_query = require("@reduxjs/toolkit/query");
|
|
30
|
+
//#region src/query/utils/capitalize.ts
|
|
51
31
|
function capitalize(str) {
|
|
52
|
-
|
|
32
|
+
return str.replace(str[0], str[0].toUpperCase());
|
|
53
33
|
}
|
|
54
|
-
|
|
55
|
-
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region src/query/utils/countObjectKeys.ts
|
|
56
36
|
function countObjectKeys(obj) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
return count;
|
|
37
|
+
let count = 0;
|
|
38
|
+
for (const _key in obj) count++;
|
|
39
|
+
return count;
|
|
62
40
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
41
|
+
//#endregion
|
|
42
|
+
//#region src/query/endpointDefinitions.ts
|
|
43
|
+
const ENDPOINT_QUERY = "query";
|
|
44
|
+
const ENDPOINT_MUTATION = "mutation";
|
|
45
|
+
const ENDPOINT_INFINITEQUERY = "infinitequery";
|
|
68
46
|
function isQueryDefinition(e) {
|
|
69
|
-
|
|
47
|
+
return e.type === ENDPOINT_QUERY;
|
|
70
48
|
}
|
|
71
49
|
function isMutationDefinition(e) {
|
|
72
|
-
|
|
50
|
+
return e.type === ENDPOINT_MUTATION;
|
|
73
51
|
}
|
|
74
52
|
function isInfiniteQueryDefinition(e) {
|
|
75
|
-
|
|
53
|
+
return e.type === ENDPOINT_INFINITEQUERY;
|
|
76
54
|
}
|
|
77
|
-
|
|
78
|
-
|
|
55
|
+
//#endregion
|
|
56
|
+
//#region src/query/tsHelpers.ts
|
|
79
57
|
function safeAssign(target, ...args) {
|
|
80
|
-
|
|
58
|
+
return Object.assign(target, ...args);
|
|
81
59
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
var UNINITIALIZED_VALUE = /* @__PURE__ */ Symbol();
|
|
88
|
-
|
|
89
|
-
// src/query/react/reactImports.ts
|
|
90
|
-
var import_react = require("react");
|
|
91
|
-
|
|
92
|
-
// src/query/react/reactReduxImports.ts
|
|
93
|
-
var import_react_redux = require("react-redux");
|
|
94
|
-
|
|
95
|
-
// src/query/react/useSerializedStableValue.ts
|
|
60
|
+
//#endregion
|
|
61
|
+
//#region src/query/react/constants.ts
|
|
62
|
+
const UNINITIALIZED_VALUE = Symbol();
|
|
63
|
+
//#endregion
|
|
64
|
+
//#region src/query/react/useSerializedStableValue.ts
|
|
96
65
|
function useStableQueryArgs(queryArgs) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}, [copy]);
|
|
104
|
-
return copy;
|
|
66
|
+
const cache = (0, react.useRef)(queryArgs);
|
|
67
|
+
const copy = (0, react.useMemo)(() => (0, _reduxjs_toolkit_query.copyWithStructuralSharing)(cache.current, queryArgs), [queryArgs]);
|
|
68
|
+
(0, react.useEffect)(() => {
|
|
69
|
+
if (cache.current !== copy) cache.current = copy;
|
|
70
|
+
}, [copy]);
|
|
71
|
+
return copy;
|
|
105
72
|
}
|
|
106
|
-
|
|
107
|
-
|
|
73
|
+
//#endregion
|
|
74
|
+
//#region src/query/react/useShallowStableValue.ts
|
|
108
75
|
function useShallowStableValue(value) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
}, [value]);
|
|
115
|
-
return (0, import_react_redux.shallowEqual)(cache.current, value) ? cache.current : value;
|
|
76
|
+
const cache = (0, react.useRef)(value);
|
|
77
|
+
(0, react.useEffect)(() => {
|
|
78
|
+
if (!(0, react_redux.shallowEqual)(cache.current, value)) cache.current = value;
|
|
79
|
+
}, [value]);
|
|
80
|
+
return (0, react_redux.shallowEqual)(cache.current, value) ? cache.current : value;
|
|
116
81
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
status: import_query.QueryStatus.pending
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
return selected;
|
|
82
|
+
//#endregion
|
|
83
|
+
//#region src/query/react/buildHooks.ts
|
|
84
|
+
const canUseDOM = () => !!(typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement !== "undefined");
|
|
85
|
+
const isDOM = /* @__PURE__ */ canUseDOM();
|
|
86
|
+
const isRunningInReactNative = () => typeof navigator !== "undefined" && navigator.product === "ReactNative";
|
|
87
|
+
const isReactNative = /* @__PURE__ */ isRunningInReactNative();
|
|
88
|
+
const getUseIsomorphicLayoutEffect = () => isDOM || isReactNative ? react.useLayoutEffect : react.useEffect;
|
|
89
|
+
const useIsomorphicLayoutEffect = /* @__PURE__ */ getUseIsomorphicLayoutEffect();
|
|
90
|
+
const noPendingQueryStateSelector = (selected) => {
|
|
91
|
+
if (selected.isUninitialized) return {
|
|
92
|
+
...selected,
|
|
93
|
+
isUninitialized: false,
|
|
94
|
+
isFetching: true,
|
|
95
|
+
isLoading: selected.data !== void 0 ? false : true,
|
|
96
|
+
status: _reduxjs_toolkit_query.QueryStatus.pending
|
|
97
|
+
};
|
|
98
|
+
return selected;
|
|
138
99
|
};
|
|
139
100
|
function pick(obj, ...keys) {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
101
|
+
const ret = {};
|
|
102
|
+
keys.forEach((key) => {
|
|
103
|
+
ret[key] = obj[key];
|
|
104
|
+
});
|
|
105
|
+
return ret;
|
|
145
106
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
refetchOnMountOrArgChange,
|
|
245
|
-
skip = false,
|
|
246
|
-
pollingInterval = 0,
|
|
247
|
-
skipPollingIfUnfocused = false,
|
|
248
|
-
...rest
|
|
249
|
-
} = {}) {
|
|
250
|
-
const {
|
|
251
|
-
initiate
|
|
252
|
-
} = api.endpoints[endpointName];
|
|
253
|
-
const dispatch = useDispatch();
|
|
254
|
-
const subscriptionSelectorsRef = (0, import_react.useRef)(void 0);
|
|
255
|
-
if (!subscriptionSelectorsRef.current) {
|
|
256
|
-
const returnedValue = dispatch(api.internalActions.internal_getRTKQSubscriptions());
|
|
257
|
-
if (true) {
|
|
258
|
-
if (typeof returnedValue !== "object" || typeof returnedValue?.type === "string") {
|
|
259
|
-
throw new Error(false ? _formatProdErrorMessage(37) : `Warning: Middleware for RTK-Query API at reducerPath "${api.reducerPath}" has not been added to the store.
|
|
107
|
+
const COMMON_HOOK_DEBUG_FIELDS = [
|
|
108
|
+
"data",
|
|
109
|
+
"status",
|
|
110
|
+
"isLoading",
|
|
111
|
+
"isSuccess",
|
|
112
|
+
"isError",
|
|
113
|
+
"error"
|
|
114
|
+
];
|
|
115
|
+
function buildHooks({ api, moduleOptions: { batch, hooks: { useDispatch, useSelector }, unstable__sideEffectsInRender, createSelector }, serializeQueryArgs, context }) {
|
|
116
|
+
const usePossiblyImmediateEffect = unstable__sideEffectsInRender ? (cb) => cb() : react.useEffect;
|
|
117
|
+
const unsubscribePromiseRef = (ref) => {
|
|
118
|
+
ref.current?.unsubscribe?.();
|
|
119
|
+
ref.current = void 0;
|
|
120
|
+
};
|
|
121
|
+
const endpointDefinitions = context.endpointDefinitions;
|
|
122
|
+
return {
|
|
123
|
+
buildQueryHooks,
|
|
124
|
+
buildInfiniteQueryHooks,
|
|
125
|
+
buildMutationHook,
|
|
126
|
+
usePrefetch
|
|
127
|
+
};
|
|
128
|
+
function queryStatePreSelector(currentState, lastResult, queryArgs) {
|
|
129
|
+
if (lastResult?.endpointName && currentState.isUninitialized) {
|
|
130
|
+
const { endpointName } = lastResult;
|
|
131
|
+
const endpointDefinition = endpointDefinitions[endpointName];
|
|
132
|
+
if (queryArgs !== _reduxjs_toolkit_query.skipToken && serializeQueryArgs({
|
|
133
|
+
queryArgs: lastResult.originalArgs,
|
|
134
|
+
endpointDefinition,
|
|
135
|
+
endpointName
|
|
136
|
+
}) === serializeQueryArgs({
|
|
137
|
+
queryArgs,
|
|
138
|
+
endpointDefinition,
|
|
139
|
+
endpointName
|
|
140
|
+
})) lastResult = void 0;
|
|
141
|
+
}
|
|
142
|
+
let data = currentState.data;
|
|
143
|
+
if (data === void 0) data = lastResult?.data;
|
|
144
|
+
const hasData = data !== void 0;
|
|
145
|
+
const isFetching = currentState.isLoading;
|
|
146
|
+
const isLoading = (!lastResult || lastResult.isLoading || lastResult.isUninitialized) && !hasData && isFetching;
|
|
147
|
+
const isSuccess = currentState.isSuccess || hasData && (isFetching && currentState.error === void 0 || currentState.isUninitialized);
|
|
148
|
+
return {
|
|
149
|
+
...currentState,
|
|
150
|
+
data,
|
|
151
|
+
currentData: currentState.data,
|
|
152
|
+
isFetching,
|
|
153
|
+
isLoading,
|
|
154
|
+
isSuccess
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
function infiniteQueryStatePreSelector(currentState, lastResult, queryArgs) {
|
|
158
|
+
if (lastResult?.endpointName && currentState.isUninitialized) {
|
|
159
|
+
const { endpointName } = lastResult;
|
|
160
|
+
const endpointDefinition = endpointDefinitions[endpointName];
|
|
161
|
+
if (queryArgs !== _reduxjs_toolkit_query.skipToken && serializeQueryArgs({
|
|
162
|
+
queryArgs: lastResult.originalArgs,
|
|
163
|
+
endpointDefinition,
|
|
164
|
+
endpointName
|
|
165
|
+
}) === serializeQueryArgs({
|
|
166
|
+
queryArgs,
|
|
167
|
+
endpointDefinition,
|
|
168
|
+
endpointName
|
|
169
|
+
})) lastResult = void 0;
|
|
170
|
+
}
|
|
171
|
+
let data = currentState.data;
|
|
172
|
+
if (data === void 0) data = lastResult?.data;
|
|
173
|
+
const hasData = data !== void 0;
|
|
174
|
+
const isFetching = currentState.isLoading;
|
|
175
|
+
const isLoading = (!lastResult || lastResult.isLoading || lastResult.isUninitialized) && !hasData && isFetching;
|
|
176
|
+
const isSuccess = currentState.isSuccess || hasData && (isFetching && currentState.error === void 0 || currentState.isUninitialized);
|
|
177
|
+
return {
|
|
178
|
+
...currentState,
|
|
179
|
+
data,
|
|
180
|
+
currentData: currentState.data,
|
|
181
|
+
isFetching,
|
|
182
|
+
isLoading,
|
|
183
|
+
isSuccess
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
function usePrefetch(endpointName, defaultOptions) {
|
|
187
|
+
const dispatch = useDispatch();
|
|
188
|
+
const stableDefaultOptions = useShallowStableValue(defaultOptions);
|
|
189
|
+
return (0, react.useCallback)((arg, options) => dispatch(api.util.prefetch(endpointName, arg, {
|
|
190
|
+
...stableDefaultOptions,
|
|
191
|
+
...options
|
|
192
|
+
})), [
|
|
193
|
+
endpointName,
|
|
194
|
+
dispatch,
|
|
195
|
+
stableDefaultOptions
|
|
196
|
+
]);
|
|
197
|
+
}
|
|
198
|
+
function useQuerySubscriptionCommonImpl(endpointName, arg, { refetchOnReconnect, refetchOnFocus, refetchOnMountOrArgChange, skip = false, pollingInterval = 0, skipPollingIfUnfocused = false, ...rest } = {}) {
|
|
199
|
+
const { initiate } = api.endpoints[endpointName];
|
|
200
|
+
const dispatch = useDispatch();
|
|
201
|
+
const subscriptionSelectorsRef = (0, react.useRef)(void 0);
|
|
202
|
+
if (!subscriptionSelectorsRef.current) {
|
|
203
|
+
const returnedValue = dispatch(api.internalActions.internal_getRTKQSubscriptions());
|
|
204
|
+
if (typeof returnedValue !== "object" || typeof returnedValue?.type === "string") throw new Error(`Warning: Middleware for RTK-Query API at reducerPath "${api.reducerPath}" has not been added to the store.
|
|
260
205
|
You must add the middleware for RTK-Query to function correctly!`);
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
}
|
|
590
|
-
if (fixedCacheKey) {
|
|
591
|
-
dispatch(api.internalActions.removeMutationResult({
|
|
592
|
-
requestId,
|
|
593
|
-
fixedCacheKey
|
|
594
|
-
}));
|
|
595
|
-
}
|
|
596
|
-
});
|
|
597
|
-
}, [dispatch, fixedCacheKey, promise, requestId]);
|
|
598
|
-
const debugValue = pick(currentState, ...COMMON_HOOK_DEBUG_FIELDS, "endpointName");
|
|
599
|
-
(0, import_react.useDebugValue)(debugValue);
|
|
600
|
-
const finalState = (0, import_react.useMemo)(() => ({
|
|
601
|
-
...currentState,
|
|
602
|
-
originalArgs,
|
|
603
|
-
reset
|
|
604
|
-
}), [currentState, originalArgs, reset]);
|
|
605
|
-
return (0, import_react.useMemo)(() => [triggerMutation, finalState], [triggerMutation, finalState]);
|
|
606
|
-
};
|
|
607
|
-
}
|
|
206
|
+
subscriptionSelectorsRef.current = returnedValue;
|
|
207
|
+
}
|
|
208
|
+
const stableArg = useStableQueryArgs(skip ? _reduxjs_toolkit_query.skipToken : arg);
|
|
209
|
+
const stableSubscriptionOptions = useShallowStableValue({
|
|
210
|
+
refetchOnReconnect,
|
|
211
|
+
refetchOnFocus,
|
|
212
|
+
pollingInterval,
|
|
213
|
+
skipPollingIfUnfocused
|
|
214
|
+
});
|
|
215
|
+
const initialPageParam = rest.initialPageParam;
|
|
216
|
+
const stableInitialPageParam = useShallowStableValue(initialPageParam);
|
|
217
|
+
const refetchCachedPages = rest.refetchCachedPages;
|
|
218
|
+
const stableRefetchCachedPages = useShallowStableValue(refetchCachedPages);
|
|
219
|
+
const promiseRef = (0, react.useRef)(void 0);
|
|
220
|
+
let { queryCacheKey, requestId } = promiseRef.current || {};
|
|
221
|
+
let currentRenderHasSubscription = false;
|
|
222
|
+
if (queryCacheKey && requestId) currentRenderHasSubscription = subscriptionSelectorsRef.current.isRequestSubscribed(queryCacheKey, requestId);
|
|
223
|
+
const subscriptionRemoved = !currentRenderHasSubscription && promiseRef.current !== void 0;
|
|
224
|
+
usePossiblyImmediateEffect(() => {
|
|
225
|
+
if (subscriptionRemoved) promiseRef.current = void 0;
|
|
226
|
+
}, [subscriptionRemoved]);
|
|
227
|
+
usePossiblyImmediateEffect(() => {
|
|
228
|
+
const lastPromise = promiseRef.current;
|
|
229
|
+
if (stableArg === _reduxjs_toolkit_query.skipToken) {
|
|
230
|
+
lastPromise?.unsubscribe();
|
|
231
|
+
promiseRef.current = void 0;
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
const lastSubscriptionOptions = promiseRef.current?.subscriptionOptions;
|
|
235
|
+
if (!lastPromise || lastPromise.arg !== stableArg) {
|
|
236
|
+
lastPromise?.unsubscribe();
|
|
237
|
+
const promise = dispatch(initiate(stableArg, {
|
|
238
|
+
subscriptionOptions: stableSubscriptionOptions,
|
|
239
|
+
forceRefetch: refetchOnMountOrArgChange,
|
|
240
|
+
...isInfiniteQueryDefinition(endpointDefinitions[endpointName]) ? {
|
|
241
|
+
initialPageParam: stableInitialPageParam,
|
|
242
|
+
refetchCachedPages: stableRefetchCachedPages
|
|
243
|
+
} : {}
|
|
244
|
+
}));
|
|
245
|
+
promiseRef.current = promise;
|
|
246
|
+
} else if (stableSubscriptionOptions !== lastSubscriptionOptions) lastPromise.updateSubscriptionOptions(stableSubscriptionOptions);
|
|
247
|
+
}, [
|
|
248
|
+
dispatch,
|
|
249
|
+
initiate,
|
|
250
|
+
refetchOnMountOrArgChange,
|
|
251
|
+
stableArg,
|
|
252
|
+
stableSubscriptionOptions,
|
|
253
|
+
subscriptionRemoved,
|
|
254
|
+
stableInitialPageParam,
|
|
255
|
+
stableRefetchCachedPages,
|
|
256
|
+
endpointName
|
|
257
|
+
]);
|
|
258
|
+
return [
|
|
259
|
+
promiseRef,
|
|
260
|
+
dispatch,
|
|
261
|
+
initiate,
|
|
262
|
+
stableSubscriptionOptions
|
|
263
|
+
];
|
|
264
|
+
}
|
|
265
|
+
function buildUseQueryState(endpointName, preSelector) {
|
|
266
|
+
const useQueryState = (arg, { skip = false, selectFromResult } = {}) => {
|
|
267
|
+
const { select } = api.endpoints[endpointName];
|
|
268
|
+
const stableArg = useStableQueryArgs(skip ? _reduxjs_toolkit_query.skipToken : arg);
|
|
269
|
+
const lastValue = (0, react.useRef)(void 0);
|
|
270
|
+
const latestDefaultResult = (0, react.useRef)(void 0);
|
|
271
|
+
const selectDefaultResult = (0, react.useMemo)(() => createSelector([
|
|
272
|
+
select(stableArg),
|
|
273
|
+
(_, lastResult) => lastResult,
|
|
274
|
+
(_) => stableArg
|
|
275
|
+
], preSelector, { memoizeOptions: { resultEqualityCheck: react_redux.shallowEqual } }), [select, stableArg]);
|
|
276
|
+
const currentState = useSelector((0, react.useMemo)(() => {
|
|
277
|
+
const selectResult = selectFromResult ? createSelector([selectDefaultResult], selectFromResult, { devModeChecks: { identityFunctionCheck: "never" } }) : selectDefaultResult;
|
|
278
|
+
return (state) => {
|
|
279
|
+
const lastResult = lastValue.current;
|
|
280
|
+
const result = selectResult(state, lastResult);
|
|
281
|
+
latestDefaultResult.current = selectDefaultResult(state, lastResult);
|
|
282
|
+
return result;
|
|
283
|
+
};
|
|
284
|
+
}, [selectDefaultResult, selectFromResult]), react_redux.shallowEqual);
|
|
285
|
+
useIsomorphicLayoutEffect(() => {
|
|
286
|
+
lastValue.current = latestDefaultResult.current;
|
|
287
|
+
});
|
|
288
|
+
return currentState;
|
|
289
|
+
};
|
|
290
|
+
return useQueryState;
|
|
291
|
+
}
|
|
292
|
+
function usePromiseRefUnsubscribeOnUnmount(promiseRef) {
|
|
293
|
+
(0, react.useEffect)(() => {
|
|
294
|
+
return () => {
|
|
295
|
+
unsubscribePromiseRef(promiseRef);
|
|
296
|
+
};
|
|
297
|
+
}, [promiseRef]);
|
|
298
|
+
}
|
|
299
|
+
function refetchOrErrorIfUnmounted(promiseRef) {
|
|
300
|
+
if (!promiseRef.current) throw new Error("Cannot refetch a query that has not been started yet.");
|
|
301
|
+
return promiseRef.current.refetch();
|
|
302
|
+
}
|
|
303
|
+
function buildQueryHooks(endpointName) {
|
|
304
|
+
const useQuerySubscription = (arg, options = {}) => {
|
|
305
|
+
const [promiseRef] = useQuerySubscriptionCommonImpl(endpointName, arg, options);
|
|
306
|
+
usePromiseRefUnsubscribeOnUnmount(promiseRef);
|
|
307
|
+
return (0, react.useMemo)(() => ({ refetch: () => refetchOrErrorIfUnmounted(promiseRef) }), [promiseRef]);
|
|
308
|
+
};
|
|
309
|
+
const useLazyQuerySubscription = ({ refetchOnReconnect, refetchOnFocus, pollingInterval = 0, skipPollingIfUnfocused = false } = {}) => {
|
|
310
|
+
const { initiate } = api.endpoints[endpointName];
|
|
311
|
+
const dispatch = useDispatch();
|
|
312
|
+
const [arg, setArg] = (0, react.useState)(UNINITIALIZED_VALUE);
|
|
313
|
+
const promiseRef = (0, react.useRef)(void 0);
|
|
314
|
+
const stableSubscriptionOptions = useShallowStableValue({
|
|
315
|
+
refetchOnReconnect,
|
|
316
|
+
refetchOnFocus,
|
|
317
|
+
pollingInterval,
|
|
318
|
+
skipPollingIfUnfocused
|
|
319
|
+
});
|
|
320
|
+
usePossiblyImmediateEffect(() => {
|
|
321
|
+
const lastSubscriptionOptions = promiseRef.current?.subscriptionOptions;
|
|
322
|
+
if (stableSubscriptionOptions !== lastSubscriptionOptions) promiseRef.current?.updateSubscriptionOptions(stableSubscriptionOptions);
|
|
323
|
+
}, [stableSubscriptionOptions]);
|
|
324
|
+
const subscriptionOptionsRef = (0, react.useRef)(stableSubscriptionOptions);
|
|
325
|
+
usePossiblyImmediateEffect(() => {
|
|
326
|
+
subscriptionOptionsRef.current = stableSubscriptionOptions;
|
|
327
|
+
}, [stableSubscriptionOptions]);
|
|
328
|
+
const trigger = (0, react.useCallback)(function(arg, preferCacheValue = false) {
|
|
329
|
+
let promise;
|
|
330
|
+
batch(() => {
|
|
331
|
+
unsubscribePromiseRef(promiseRef);
|
|
332
|
+
promiseRef.current = promise = dispatch(initiate(arg, {
|
|
333
|
+
subscriptionOptions: subscriptionOptionsRef.current,
|
|
334
|
+
forceRefetch: !preferCacheValue
|
|
335
|
+
}));
|
|
336
|
+
setArg(arg);
|
|
337
|
+
});
|
|
338
|
+
return promise;
|
|
339
|
+
}, [dispatch, initiate]);
|
|
340
|
+
const reset = (0, react.useCallback)(() => {
|
|
341
|
+
if (promiseRef.current?.queryCacheKey) dispatch(api.internalActions.removeQueryResult({ queryCacheKey: promiseRef.current?.queryCacheKey }));
|
|
342
|
+
}, [dispatch]);
|
|
343
|
+
(0, react.useEffect)(() => {
|
|
344
|
+
return () => {
|
|
345
|
+
unsubscribePromiseRef(promiseRef);
|
|
346
|
+
};
|
|
347
|
+
}, []);
|
|
348
|
+
(0, react.useEffect)(() => {
|
|
349
|
+
if (arg !== UNINITIALIZED_VALUE && !promiseRef.current) trigger(arg, true);
|
|
350
|
+
}, [arg, trigger]);
|
|
351
|
+
return (0, react.useMemo)(() => [
|
|
352
|
+
trigger,
|
|
353
|
+
arg,
|
|
354
|
+
{ reset }
|
|
355
|
+
], [
|
|
356
|
+
trigger,
|
|
357
|
+
arg,
|
|
358
|
+
reset
|
|
359
|
+
]);
|
|
360
|
+
};
|
|
361
|
+
const useQueryState = buildUseQueryState(endpointName, queryStatePreSelector);
|
|
362
|
+
return {
|
|
363
|
+
useQueryState,
|
|
364
|
+
useQuerySubscription,
|
|
365
|
+
useLazyQuerySubscription,
|
|
366
|
+
useLazyQuery(options) {
|
|
367
|
+
const [trigger, arg, { reset }] = useLazyQuerySubscription(options);
|
|
368
|
+
const queryStateResults = useQueryState(arg, {
|
|
369
|
+
...options,
|
|
370
|
+
skip: arg === UNINITIALIZED_VALUE
|
|
371
|
+
});
|
|
372
|
+
const info = (0, react.useMemo)(() => ({ lastArg: arg }), [arg]);
|
|
373
|
+
return (0, react.useMemo)(() => [
|
|
374
|
+
trigger,
|
|
375
|
+
{
|
|
376
|
+
...queryStateResults,
|
|
377
|
+
reset
|
|
378
|
+
},
|
|
379
|
+
info
|
|
380
|
+
], [
|
|
381
|
+
trigger,
|
|
382
|
+
queryStateResults,
|
|
383
|
+
reset,
|
|
384
|
+
info
|
|
385
|
+
]);
|
|
386
|
+
},
|
|
387
|
+
useQuery(arg, options) {
|
|
388
|
+
const querySubscriptionResults = useQuerySubscription(arg, options);
|
|
389
|
+
const queryStateResults = useQueryState(arg, {
|
|
390
|
+
selectFromResult: arg === _reduxjs_toolkit_query.skipToken || options?.skip ? void 0 : noPendingQueryStateSelector,
|
|
391
|
+
...options
|
|
392
|
+
});
|
|
393
|
+
const debugValue = pick(queryStateResults, ...COMMON_HOOK_DEBUG_FIELDS);
|
|
394
|
+
(0, react.useDebugValue)(debugValue);
|
|
395
|
+
return (0, react.useMemo)(() => ({
|
|
396
|
+
...queryStateResults,
|
|
397
|
+
...querySubscriptionResults
|
|
398
|
+
}), [queryStateResults, querySubscriptionResults]);
|
|
399
|
+
}
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
function buildInfiniteQueryHooks(endpointName) {
|
|
403
|
+
const useInfiniteQuerySubscription = (arg, options = {}) => {
|
|
404
|
+
const [promiseRef, dispatch, initiate, stableSubscriptionOptions] = useQuerySubscriptionCommonImpl(endpointName, arg, options);
|
|
405
|
+
const subscriptionOptionsRef = (0, react.useRef)(stableSubscriptionOptions);
|
|
406
|
+
usePossiblyImmediateEffect(() => {
|
|
407
|
+
subscriptionOptionsRef.current = stableSubscriptionOptions;
|
|
408
|
+
}, [stableSubscriptionOptions]);
|
|
409
|
+
const hookRefetchCachedPages = options.refetchCachedPages;
|
|
410
|
+
const stableHookRefetchCachedPages = useShallowStableValue(hookRefetchCachedPages);
|
|
411
|
+
const trigger = (0, react.useCallback)(function(arg, direction) {
|
|
412
|
+
let promise;
|
|
413
|
+
batch(() => {
|
|
414
|
+
unsubscribePromiseRef(promiseRef);
|
|
415
|
+
promiseRef.current = promise = dispatch(initiate(arg, {
|
|
416
|
+
subscriptionOptions: subscriptionOptionsRef.current,
|
|
417
|
+
direction
|
|
418
|
+
}));
|
|
419
|
+
});
|
|
420
|
+
return promise;
|
|
421
|
+
}, [
|
|
422
|
+
promiseRef,
|
|
423
|
+
dispatch,
|
|
424
|
+
initiate
|
|
425
|
+
]);
|
|
426
|
+
usePromiseRefUnsubscribeOnUnmount(promiseRef);
|
|
427
|
+
const stableArg = useStableQueryArgs(options.skip ? _reduxjs_toolkit_query.skipToken : arg);
|
|
428
|
+
const refetch = (0, react.useCallback)((options) => {
|
|
429
|
+
if (!promiseRef.current) throw new Error("Cannot refetch a query that has not been started yet.");
|
|
430
|
+
const mergedOptions = { refetchCachedPages: options?.refetchCachedPages ?? stableHookRefetchCachedPages };
|
|
431
|
+
return promiseRef.current.refetch(mergedOptions);
|
|
432
|
+
}, [promiseRef, stableHookRefetchCachedPages]);
|
|
433
|
+
return (0, react.useMemo)(() => {
|
|
434
|
+
const fetchNextPage = () => {
|
|
435
|
+
return trigger(stableArg, "forward");
|
|
436
|
+
};
|
|
437
|
+
const fetchPreviousPage = () => {
|
|
438
|
+
return trigger(stableArg, "backward");
|
|
439
|
+
};
|
|
440
|
+
return {
|
|
441
|
+
trigger,
|
|
442
|
+
refetch,
|
|
443
|
+
fetchNextPage,
|
|
444
|
+
fetchPreviousPage
|
|
445
|
+
};
|
|
446
|
+
}, [
|
|
447
|
+
refetch,
|
|
448
|
+
trigger,
|
|
449
|
+
stableArg
|
|
450
|
+
]);
|
|
451
|
+
};
|
|
452
|
+
const useInfiniteQueryState = buildUseQueryState(endpointName, infiniteQueryStatePreSelector);
|
|
453
|
+
return {
|
|
454
|
+
useInfiniteQueryState,
|
|
455
|
+
useInfiniteQuerySubscription,
|
|
456
|
+
useInfiniteQuery(arg, options) {
|
|
457
|
+
const { refetch, fetchNextPage, fetchPreviousPage } = useInfiniteQuerySubscription(arg, options);
|
|
458
|
+
const queryStateResults = useInfiniteQueryState(arg, {
|
|
459
|
+
selectFromResult: arg === _reduxjs_toolkit_query.skipToken || options?.skip ? void 0 : noPendingQueryStateSelector,
|
|
460
|
+
...options
|
|
461
|
+
});
|
|
462
|
+
const debugValue = pick(queryStateResults, ...COMMON_HOOK_DEBUG_FIELDS, "hasNextPage", "hasPreviousPage");
|
|
463
|
+
(0, react.useDebugValue)(debugValue);
|
|
464
|
+
return (0, react.useMemo)(() => ({
|
|
465
|
+
...queryStateResults,
|
|
466
|
+
fetchNextPage,
|
|
467
|
+
fetchPreviousPage,
|
|
468
|
+
refetch
|
|
469
|
+
}), [
|
|
470
|
+
queryStateResults,
|
|
471
|
+
fetchNextPage,
|
|
472
|
+
fetchPreviousPage,
|
|
473
|
+
refetch
|
|
474
|
+
]);
|
|
475
|
+
}
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
function buildMutationHook(name) {
|
|
479
|
+
return ({ selectFromResult, fixedCacheKey } = {}) => {
|
|
480
|
+
const { select, initiate } = api.endpoints[name];
|
|
481
|
+
const dispatch = useDispatch();
|
|
482
|
+
const [promise, setPromise] = (0, react.useState)();
|
|
483
|
+
(0, react.useEffect)(() => () => {
|
|
484
|
+
if (!promise?.arg.fixedCacheKey) promise?.reset();
|
|
485
|
+
}, [promise]);
|
|
486
|
+
const triggerMutation = (0, react.useCallback)(function(arg) {
|
|
487
|
+
const promise = dispatch(initiate(arg, { fixedCacheKey }));
|
|
488
|
+
setPromise(promise);
|
|
489
|
+
return promise;
|
|
490
|
+
}, [
|
|
491
|
+
dispatch,
|
|
492
|
+
initiate,
|
|
493
|
+
fixedCacheKey
|
|
494
|
+
]);
|
|
495
|
+
const { requestId } = promise || {};
|
|
496
|
+
const selectDefaultResult = (0, react.useMemo)(() => select({
|
|
497
|
+
fixedCacheKey,
|
|
498
|
+
requestId: promise?.requestId
|
|
499
|
+
}), [
|
|
500
|
+
fixedCacheKey,
|
|
501
|
+
promise,
|
|
502
|
+
select
|
|
503
|
+
]);
|
|
504
|
+
const currentState = useSelector((0, react.useMemo)(() => selectFromResult ? createSelector([selectDefaultResult], selectFromResult) : selectDefaultResult, [selectFromResult, selectDefaultResult]), react_redux.shallowEqual);
|
|
505
|
+
const originalArgs = fixedCacheKey == null ? promise?.arg.originalArgs : void 0;
|
|
506
|
+
const reset = (0, react.useCallback)(() => {
|
|
507
|
+
batch(() => {
|
|
508
|
+
if (promise) setPromise(void 0);
|
|
509
|
+
if (fixedCacheKey) dispatch(api.internalActions.removeMutationResult({
|
|
510
|
+
requestId,
|
|
511
|
+
fixedCacheKey
|
|
512
|
+
}));
|
|
513
|
+
});
|
|
514
|
+
}, [
|
|
515
|
+
dispatch,
|
|
516
|
+
fixedCacheKey,
|
|
517
|
+
promise,
|
|
518
|
+
requestId
|
|
519
|
+
]);
|
|
520
|
+
const debugValue = pick(currentState, ...COMMON_HOOK_DEBUG_FIELDS, "endpointName");
|
|
521
|
+
(0, react.useDebugValue)(debugValue);
|
|
522
|
+
const finalState = (0, react.useMemo)(() => ({
|
|
523
|
+
...currentState,
|
|
524
|
+
originalArgs,
|
|
525
|
+
reset
|
|
526
|
+
}), [
|
|
527
|
+
currentState,
|
|
528
|
+
originalArgs,
|
|
529
|
+
reset
|
|
530
|
+
]);
|
|
531
|
+
return (0, react.useMemo)(() => [triggerMutation, finalState], [triggerMutation, finalState]);
|
|
532
|
+
};
|
|
533
|
+
}
|
|
608
534
|
}
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
useLazyQuerySubscription,
|
|
684
|
-
useQueryState,
|
|
685
|
-
useQuerySubscription
|
|
686
|
-
});
|
|
687
|
-
api[`use${capitalize(endpointName)}Query`] = useQuery;
|
|
688
|
-
api[`useLazy${capitalize(endpointName)}Query`] = useLazyQuery;
|
|
689
|
-
}
|
|
690
|
-
if (isMutationDefinition(definition)) {
|
|
691
|
-
const useMutation = buildMutationHook(endpointName);
|
|
692
|
-
safeAssign(anyApi.endpoints[endpointName], {
|
|
693
|
-
useMutation
|
|
694
|
-
});
|
|
695
|
-
api[`use${capitalize(endpointName)}Mutation`] = useMutation;
|
|
696
|
-
} else if (isInfiniteQueryDefinition(definition)) {
|
|
697
|
-
const {
|
|
698
|
-
useInfiniteQuery,
|
|
699
|
-
useInfiniteQuerySubscription,
|
|
700
|
-
useInfiniteQueryState
|
|
701
|
-
} = buildInfiniteQueryHooks(endpointName);
|
|
702
|
-
safeAssign(anyApi.endpoints[endpointName], {
|
|
703
|
-
useInfiniteQuery,
|
|
704
|
-
useInfiniteQuerySubscription,
|
|
705
|
-
useInfiniteQueryState
|
|
706
|
-
});
|
|
707
|
-
api[`use${capitalize(endpointName)}InfiniteQuery`] = useInfiniteQuery;
|
|
708
|
-
}
|
|
709
|
-
}
|
|
710
|
-
};
|
|
711
|
-
}
|
|
712
|
-
};
|
|
535
|
+
//#endregion
|
|
536
|
+
//#region src/query/react/module.ts
|
|
537
|
+
const reactHooksModuleName = /* @__PURE__ */ Symbol();
|
|
538
|
+
const reactHooksModule = ({ batch = react_redux.batch, hooks = {
|
|
539
|
+
useDispatch: react_redux.useDispatch,
|
|
540
|
+
useSelector: react_redux.useSelector,
|
|
541
|
+
useStore: react_redux.useStore
|
|
542
|
+
}, createSelector = reselect.createSelector, unstable__sideEffectsInRender = false, ...rest } = {}) => {
|
|
543
|
+
{
|
|
544
|
+
const hookNames = [
|
|
545
|
+
"useDispatch",
|
|
546
|
+
"useSelector",
|
|
547
|
+
"useStore"
|
|
548
|
+
];
|
|
549
|
+
let warned = false;
|
|
550
|
+
for (const hookName of hookNames) {
|
|
551
|
+
if (countObjectKeys(rest) > 0) {
|
|
552
|
+
if (rest[hookName]) {
|
|
553
|
+
if (!warned) {
|
|
554
|
+
console.warn("As of RTK 2.0, the hooks now need to be specified as one object, provided under a `hooks` key:\n`reactHooksModule({ hooks: { useDispatch, useSelector, useStore } })`");
|
|
555
|
+
warned = true;
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
hooks[hookName] = rest[hookName];
|
|
559
|
+
}
|
|
560
|
+
if (typeof hooks[hookName] !== "function") throw new Error(`When using custom hooks for context, all ${hookNames.length} hooks need to be provided: ${hookNames.join(", ")}.\nHook ${hookName} was either not provided or not a function.`);
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
return {
|
|
564
|
+
name: reactHooksModuleName,
|
|
565
|
+
init(api, { serializeQueryArgs }, context) {
|
|
566
|
+
const anyApi = api;
|
|
567
|
+
const { buildQueryHooks, buildInfiniteQueryHooks, buildMutationHook, usePrefetch } = buildHooks({
|
|
568
|
+
api,
|
|
569
|
+
moduleOptions: {
|
|
570
|
+
batch,
|
|
571
|
+
hooks,
|
|
572
|
+
unstable__sideEffectsInRender,
|
|
573
|
+
createSelector
|
|
574
|
+
},
|
|
575
|
+
serializeQueryArgs,
|
|
576
|
+
context
|
|
577
|
+
});
|
|
578
|
+
safeAssign(anyApi, { usePrefetch });
|
|
579
|
+
safeAssign(context, { batch });
|
|
580
|
+
return { injectEndpoint(endpointName, definition) {
|
|
581
|
+
if (isQueryDefinition(definition)) {
|
|
582
|
+
const { useQuery, useLazyQuery, useLazyQuerySubscription, useQueryState, useQuerySubscription } = buildQueryHooks(endpointName);
|
|
583
|
+
safeAssign(anyApi.endpoints[endpointName], {
|
|
584
|
+
useQuery,
|
|
585
|
+
useLazyQuery,
|
|
586
|
+
useLazyQuerySubscription,
|
|
587
|
+
useQueryState,
|
|
588
|
+
useQuerySubscription
|
|
589
|
+
});
|
|
590
|
+
api[`use${capitalize(endpointName)}Query`] = useQuery;
|
|
591
|
+
api[`useLazy${capitalize(endpointName)}Query`] = useLazyQuery;
|
|
592
|
+
}
|
|
593
|
+
if (isMutationDefinition(definition)) {
|
|
594
|
+
const useMutation = buildMutationHook(endpointName);
|
|
595
|
+
safeAssign(anyApi.endpoints[endpointName], { useMutation });
|
|
596
|
+
api[`use${capitalize(endpointName)}Mutation`] = useMutation;
|
|
597
|
+
} else if (isInfiniteQueryDefinition(definition)) {
|
|
598
|
+
const { useInfiniteQuery, useInfiniteQuerySubscription, useInfiniteQueryState } = buildInfiniteQueryHooks(endpointName);
|
|
599
|
+
safeAssign(anyApi.endpoints[endpointName], {
|
|
600
|
+
useInfiniteQuery,
|
|
601
|
+
useInfiniteQuerySubscription,
|
|
602
|
+
useInfiniteQueryState
|
|
603
|
+
});
|
|
604
|
+
api[`use${capitalize(endpointName)}InfiniteQuery`] = useInfiniteQuery;
|
|
605
|
+
}
|
|
606
|
+
} };
|
|
607
|
+
}
|
|
608
|
+
};
|
|
713
609
|
};
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
__reExport(react_exports, require("@reduxjs/toolkit/query"), module.exports);
|
|
717
|
-
|
|
718
|
-
// src/query/react/ApiProvider.tsx
|
|
719
|
-
var import_toolkit3 = require("@reduxjs/toolkit");
|
|
720
|
-
var React = __toESM(require("react"));
|
|
610
|
+
//#endregion
|
|
611
|
+
//#region src/query/react/ApiProvider.tsx
|
|
721
612
|
function ApiProvider(props) {
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
(0, import_react.useEffect)(() => props.setupListeners === false ? void 0 : (0, import_query.setupListeners)(store.dispatch, props.setupListeners), [props.setupListeners, store.dispatch]);
|
|
734
|
-
return /* @__PURE__ */ React.createElement(import_react_redux.Provider, { store, context }, props.children);
|
|
613
|
+
const context = props.context || react_redux.ReactReduxContext;
|
|
614
|
+
if ((0, react.useContext)(context)) throw new Error("Existing Redux context detected. If you already have a store set up, please use the traditional Redux setup.");
|
|
615
|
+
const [store] = react.useState(() => (0, _reduxjs_toolkit.configureStore)({
|
|
616
|
+
reducer: { [props.api.reducerPath]: props.api.reducer },
|
|
617
|
+
middleware: (gDM) => gDM().concat(props.api.middleware)
|
|
618
|
+
}));
|
|
619
|
+
(0, react.useEffect)(() => props.setupListeners === false ? void 0 : (0, _reduxjs_toolkit_query.setupListeners)(store.dispatch, props.setupListeners), [props.setupListeners, store.dispatch]);
|
|
620
|
+
return /* @__PURE__ */ react.createElement(react_redux.Provider, {
|
|
621
|
+
store,
|
|
622
|
+
context
|
|
623
|
+
}, props.children);
|
|
735
624
|
}
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
625
|
+
//#endregion
|
|
626
|
+
//#region src/query/react/index.ts
|
|
627
|
+
const createApi = /* @__PURE__ */ (0, _reduxjs_toolkit_query.buildCreateApi)((0, _reduxjs_toolkit_query.coreModule)(), reactHooksModule());
|
|
628
|
+
//#endregion
|
|
629
|
+
exports.ApiProvider = ApiProvider;
|
|
630
|
+
exports.UNINITIALIZED_VALUE = UNINITIALIZED_VALUE;
|
|
631
|
+
exports.createApi = createApi;
|
|
632
|
+
exports.reactHooksModule = reactHooksModule;
|
|
633
|
+
exports.reactHooksModuleName = reactHooksModuleName;
|
|
634
|
+
Object.keys(_reduxjs_toolkit_query).forEach(function(k) {
|
|
635
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
636
|
+
enumerable: true,
|
|
637
|
+
get: function() {
|
|
638
|
+
return _reduxjs_toolkit_query[k];
|
|
639
|
+
}
|
|
640
|
+
});
|
|
747
641
|
});
|
|
642
|
+
|
|
748
643
|
//# sourceMappingURL=rtk-query-react.development.cjs.map
|