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