1 | var __spreadArray = (this && this.__spreadArray) || function (to, from) {
|
2 | for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
|
3 | to[j] = from[i];
|
4 | return to;
|
5 | };
|
6 | var __create = Object.create;
|
7 | var __defProp = Object.defineProperty;
|
8 | var __defProps = Object.defineProperties;
|
9 | var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
10 | var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
11 | var __getOwnPropNames = Object.getOwnPropertyNames;
|
12 | var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
13 | var __getProtoOf = Object.getPrototypeOf;
|
14 | var __hasOwnProp = Object.prototype.hasOwnProperty;
|
15 | var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
16 | var __defNormalProp = function (obj, key, value) { return key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value: value }) : obj[key] = value; };
|
17 | var __spreadValues = function (a, b) {
|
18 | for (var prop in b || (b = {}))
|
19 | if (__hasOwnProp.call(b, prop))
|
20 | __defNormalProp(a, prop, b[prop]);
|
21 | if (__getOwnPropSymbols)
|
22 | for (var _i = 0, _c = __getOwnPropSymbols(b); _i < _c.length; _i++) {
|
23 | var prop = _c[_i];
|
24 | if (__propIsEnum.call(b, prop))
|
25 | __defNormalProp(a, prop, b[prop]);
|
26 | }
|
27 | return a;
|
28 | };
|
29 | var __spreadProps = function (a, b) { return __defProps(a, __getOwnPropDescs(b)); };
|
30 | var __markAsModule = function (target) { return __defProp(target, "__esModule", { value: true }); };
|
31 | var __export = function (target, all) {
|
32 | for (var name in all)
|
33 | __defProp(target, name, { get: all[name], enumerable: true });
|
34 | };
|
35 | var __reExport = function (target, module2, desc) {
|
36 | if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
37 | var _loop_1 = function (key) {
|
38 | if (!__hasOwnProp.call(target, key) && key !== "default")
|
39 | __defProp(target, key, { get: function () { return module2[key]; }, enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
40 | };
|
41 | for (var _i = 0, _c = __getOwnPropNames(module2); _i < _c.length; _i++) {
|
42 | var key = _c[_i];
|
43 | _loop_1(key);
|
44 | }
|
45 | }
|
46 | return target;
|
47 | };
|
48 | var __toModule = function (module2) {
|
49 | return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: function () { return module2.default; }, enumerable: true } : { value: module2, enumerable: true })), module2);
|
50 | };
|
51 |
|
52 | __markAsModule(exports);
|
53 | __export(exports, {
|
54 | ApiProvider: function () { return ApiProvider; },
|
55 | createApi: function () { return createApi; },
|
56 | reactHooksModule: function () { return reactHooksModule; }
|
57 | });
|
58 | var import_query3 = __toModule(require("@reduxjs/toolkit/query"));
|
59 |
|
60 | var import_toolkit2 = __toModule(require("@reduxjs/toolkit"));
|
61 | var import_react3 = __toModule(require("react"));
|
62 | var import_query = __toModule(require("@reduxjs/toolkit/query"));
|
63 | var import_react_redux2 = __toModule(require("react-redux"));
|
64 |
|
65 | var import_react = __toModule(require("react"));
|
66 | function useStableQueryArgs(queryArgs, serialize, endpointDefinition, endpointName) {
|
67 | var incoming = (0, import_react.useMemo)(function () { return ({
|
68 | queryArgs: queryArgs,
|
69 | serialized: typeof queryArgs == "object" ? serialize({ queryArgs: queryArgs, endpointDefinition: endpointDefinition, endpointName: endpointName }) : queryArgs
|
70 | }); }, [queryArgs, serialize, endpointDefinition, endpointName]);
|
71 | var cache = (0, import_react.useRef)(incoming);
|
72 | (0, import_react.useEffect)(function () {
|
73 | if (cache.current.serialized !== incoming.serialized) {
|
74 | cache.current = incoming;
|
75 | }
|
76 | }, [incoming]);
|
77 | return cache.current.serialized === incoming.serialized ? cache.current.queryArgs : queryArgs;
|
78 | }
|
79 |
|
80 | var UNINITIALIZED_VALUE = Symbol();
|
81 |
|
82 | var import_react2 = __toModule(require("react"));
|
83 | var import_react_redux = __toModule(require("react-redux"));
|
84 | function useShallowStableValue(value) {
|
85 | var cache = (0, import_react2.useRef)(value);
|
86 | (0, import_react2.useEffect)(function () {
|
87 | if (!(0, import_react_redux.shallowEqual)(cache.current, value)) {
|
88 | cache.current = value;
|
89 | }
|
90 | }, [value]);
|
91 | return (0, import_react_redux.shallowEqual)(cache.current, value) ? cache.current : value;
|
92 | }
|
93 |
|
94 | var import_toolkit = __toModule(require("@reduxjs/toolkit"));
|
95 | var defaultSerializeQueryArgs = function (_c) {
|
96 | var endpointName = _c.endpointName, queryArgs = _c.queryArgs;
|
97 | return endpointName + "(" + JSON.stringify(queryArgs, function (key, value) { return (0, import_toolkit.isPlainObject)(value) ? Object.keys(value).sort().reduce(function (acc, key2) {
|
98 | acc[key2] = value[key2];
|
99 | return acc;
|
100 | }, {}) : value; }) + ")";
|
101 | };
|
102 |
|
103 | var useIsomorphicLayoutEffect = typeof window !== "undefined" && !!window.document && !!window.document.createElement ? import_react3.useLayoutEffect : import_react3.useEffect;
|
104 | var defaultMutationStateSelector = function (x) { return x; };
|
105 | var noPendingQueryStateSelector = function (selected) {
|
106 | if (selected.isUninitialized) {
|
107 | return __spreadProps(__spreadValues({}, selected), {
|
108 | isUninitialized: false,
|
109 | isFetching: true,
|
110 | isLoading: selected.data !== void 0 ? false : true,
|
111 | status: import_query.QueryStatus.pending
|
112 | });
|
113 | }
|
114 | return selected;
|
115 | };
|
116 | function buildHooks(_c) {
|
117 | var api = _c.api, _d = _c.moduleOptions, batch = _d.batch, useDispatch = _d.useDispatch, useSelector = _d.useSelector, useStore = _d.useStore, unstable__sideEffectsInRender = _d.unstable__sideEffectsInRender, serializeQueryArgs = _c.serializeQueryArgs, context = _c.context;
|
118 | var usePossiblyImmediateEffect = unstable__sideEffectsInRender ? function (cb) { return cb(); } : import_react3.useEffect;
|
119 | return { buildQueryHooks: buildQueryHooks, buildMutationHook: buildMutationHook, usePrefetch: usePrefetch };
|
120 | function queryStatePreSelector(currentState, lastResult, queryArgs) {
|
121 | if ((lastResult == null ? void 0 : lastResult.endpointName) && currentState.isUninitialized) {
|
122 | var endpointName = lastResult.endpointName;
|
123 | var endpointDefinition = context.endpointDefinitions[endpointName];
|
124 | if (serializeQueryArgs({
|
125 | queryArgs: lastResult.originalArgs,
|
126 | endpointDefinition: endpointDefinition,
|
127 | endpointName: endpointName
|
128 | }) === serializeQueryArgs({
|
129 | queryArgs: queryArgs,
|
130 | endpointDefinition: endpointDefinition,
|
131 | endpointName: endpointName
|
132 | }))
|
133 | lastResult = void 0;
|
134 | }
|
135 | if (queryArgs === import_query.skipToken) {
|
136 | lastResult = void 0;
|
137 | }
|
138 | var data = currentState.isSuccess ? currentState.data : lastResult == null ? void 0 : lastResult.data;
|
139 | if (data === void 0)
|
140 | data = currentState.data;
|
141 | var hasData = data !== void 0;
|
142 | var isFetching = currentState.isLoading;
|
143 | var isLoading = !hasData && isFetching;
|
144 | var isSuccess = currentState.isSuccess || isFetching && hasData;
|
145 | return __spreadProps(__spreadValues({}, currentState), {
|
146 | data: data,
|
147 | currentData: currentState.data,
|
148 | isFetching: isFetching,
|
149 | isLoading: isLoading,
|
150 | isSuccess: isSuccess
|
151 | });
|
152 | }
|
153 | function usePrefetch(endpointName, defaultOptions) {
|
154 | var dispatch = useDispatch();
|
155 | var stableDefaultOptions = useShallowStableValue(defaultOptions);
|
156 | return (0, import_react3.useCallback)(function (arg, options) { return dispatch(api.util.prefetch(endpointName, arg, __spreadValues(__spreadValues({}, stableDefaultOptions), options))); }, [endpointName, dispatch, stableDefaultOptions]);
|
157 | }
|
158 | function buildQueryHooks(name) {
|
159 | var useQuerySubscription = function (arg, _c) {
|
160 | var _d = _c === void 0 ? {} : _c, refetchOnReconnect = _d.refetchOnReconnect, refetchOnFocus = _d.refetchOnFocus, refetchOnMountOrArgChange = _d.refetchOnMountOrArgChange, _e = _d.skip, skip = _e === void 0 ? false : _e, _f = _d.pollingInterval, pollingInterval = _f === void 0 ? 0 : _f;
|
161 | var initiate = api.endpoints[name].initiate;
|
162 | var dispatch = useDispatch();
|
163 | var stableArg = useStableQueryArgs(skip ? import_query.skipToken : arg, defaultSerializeQueryArgs, context.endpointDefinitions[name], name);
|
164 | var stableSubscriptionOptions = useShallowStableValue({
|
165 | refetchOnReconnect: refetchOnReconnect,
|
166 | refetchOnFocus: refetchOnFocus,
|
167 | pollingInterval: pollingInterval
|
168 | });
|
169 | var lastRenderHadSubscription = (0, import_react3.useRef)(false);
|
170 | var promiseRef = (0, import_react3.useRef)();
|
171 | var _g = promiseRef.current || {}, queryCacheKey = _g.queryCacheKey, requestId = _g.requestId;
|
172 | var currentRenderHasSubscription = false;
|
173 | if (queryCacheKey && requestId) {
|
174 | var returnedValue = dispatch(api.internalActions.internal_probeSubscription({
|
175 | queryCacheKey: queryCacheKey,
|
176 | requestId: requestId
|
177 | }));
|
178 | if (true) {
|
179 | if (typeof returnedValue !== "boolean") {
|
180 | throw new Error("Warning: Middleware for RTK-Query API at reducerPath \"" + api.reducerPath + "\" has not been added to the store.\n You must add the middleware for RTK-Query to function correctly!");
|
181 | }
|
182 | }
|
183 | currentRenderHasSubscription = !!returnedValue;
|
184 | }
|
185 | var subscriptionRemoved = !currentRenderHasSubscription && lastRenderHadSubscription.current;
|
186 | usePossiblyImmediateEffect(function () {
|
187 | lastRenderHadSubscription.current = currentRenderHasSubscription;
|
188 | });
|
189 | usePossiblyImmediateEffect(function () {
|
190 | promiseRef.current = void 0;
|
191 | }, [subscriptionRemoved]);
|
192 | usePossiblyImmediateEffect(function () {
|
193 | var _a;
|
194 | var lastPromise = promiseRef.current;
|
195 | if (typeof process !== "undefined" && false) {
|
196 | console.log(subscriptionRemoved);
|
197 | }
|
198 | if (stableArg === import_query.skipToken) {
|
199 | lastPromise == null ? void 0 : lastPromise.unsubscribe();
|
200 | promiseRef.current = void 0;
|
201 | return;
|
202 | }
|
203 | var lastSubscriptionOptions = (_a = promiseRef.current) == null ? void 0 : _a.subscriptionOptions;
|
204 | if (!lastPromise || lastPromise.arg !== stableArg) {
|
205 | lastPromise == null ? void 0 : lastPromise.unsubscribe();
|
206 | var promise = dispatch(initiate(stableArg, {
|
207 | subscriptionOptions: stableSubscriptionOptions,
|
208 | forceRefetch: refetchOnMountOrArgChange
|
209 | }));
|
210 | promiseRef.current = promise;
|
211 | }
|
212 | else if (stableSubscriptionOptions !== lastSubscriptionOptions) {
|
213 | lastPromise.updateSubscriptionOptions(stableSubscriptionOptions);
|
214 | }
|
215 | }, [
|
216 | dispatch,
|
217 | initiate,
|
218 | refetchOnMountOrArgChange,
|
219 | stableArg,
|
220 | stableSubscriptionOptions,
|
221 | subscriptionRemoved
|
222 | ]);
|
223 | (0, import_react3.useEffect)(function () {
|
224 | return function () {
|
225 | var _a;
|
226 | (_a = promiseRef.current) == null ? void 0 : _a.unsubscribe();
|
227 | promiseRef.current = void 0;
|
228 | };
|
229 | }, []);
|
230 | return (0, import_react3.useMemo)(function () { return ({
|
231 | refetch: function () {
|
232 | var _a;
|
233 | if (!promiseRef.current)
|
234 | throw new Error("Cannot refetch a query that has not been started yet.");
|
235 | return (_a = promiseRef.current) == null ? void 0 : _a.refetch();
|
236 | }
|
237 | }); }, []);
|
238 | };
|
239 | var useLazyQuerySubscription = function (_c) {
|
240 | var _d = _c === void 0 ? {} : _c, refetchOnReconnect = _d.refetchOnReconnect, refetchOnFocus = _d.refetchOnFocus, _e = _d.pollingInterval, pollingInterval = _e === void 0 ? 0 : _e;
|
241 | var initiate = api.endpoints[name].initiate;
|
242 | var dispatch = useDispatch();
|
243 | var _f = (0, import_react3.useState)(UNINITIALIZED_VALUE), arg = _f[0], setArg = _f[1];
|
244 | var promiseRef = (0, import_react3.useRef)();
|
245 | var stableSubscriptionOptions = useShallowStableValue({
|
246 | refetchOnReconnect: refetchOnReconnect,
|
247 | refetchOnFocus: refetchOnFocus,
|
248 | pollingInterval: pollingInterval
|
249 | });
|
250 | usePossiblyImmediateEffect(function () {
|
251 | var _a, _b;
|
252 | var lastSubscriptionOptions = (_a = promiseRef.current) == null ? void 0 : _a.subscriptionOptions;
|
253 | if (stableSubscriptionOptions !== lastSubscriptionOptions) {
|
254 | (_b = promiseRef.current) == null ? void 0 : _b.updateSubscriptionOptions(stableSubscriptionOptions);
|
255 | }
|
256 | }, [stableSubscriptionOptions]);
|
257 | var subscriptionOptionsRef = (0, import_react3.useRef)(stableSubscriptionOptions);
|
258 | usePossiblyImmediateEffect(function () {
|
259 | subscriptionOptionsRef.current = stableSubscriptionOptions;
|
260 | }, [stableSubscriptionOptions]);
|
261 | var trigger = (0, import_react3.useCallback)(function (arg2, preferCacheValue) {
|
262 | if (preferCacheValue === void 0) { preferCacheValue = false; }
|
263 | var promise;
|
264 | batch(function () {
|
265 | var _a;
|
266 | (_a = promiseRef.current) == null ? void 0 : _a.unsubscribe();
|
267 | promiseRef.current = promise = dispatch(initiate(arg2, {
|
268 | subscriptionOptions: subscriptionOptionsRef.current,
|
269 | forceRefetch: !preferCacheValue
|
270 | }));
|
271 | setArg(arg2);
|
272 | });
|
273 | return promise;
|
274 | }, [dispatch, initiate]);
|
275 | (0, import_react3.useEffect)(function () {
|
276 | return function () {
|
277 | var _a;
|
278 | (_a = promiseRef == null ? void 0 : promiseRef.current) == null ? void 0 : _a.unsubscribe();
|
279 | };
|
280 | }, []);
|
281 | (0, import_react3.useEffect)(function () {
|
282 | if (arg !== UNINITIALIZED_VALUE && !promiseRef.current) {
|
283 | trigger(arg, true);
|
284 | }
|
285 | }, [arg, trigger]);
|
286 | return (0, import_react3.useMemo)(function () { return [trigger, arg]; }, [trigger, arg]);
|
287 | };
|
288 | var useQueryState = function (arg, _c) {
|
289 | var _d = _c === void 0 ? {} : _c, _e = _d.skip, skip = _e === void 0 ? false : _e, selectFromResult = _d.selectFromResult;
|
290 | var select = api.endpoints[name].select;
|
291 | var stableArg = useStableQueryArgs(skip ? import_query.skipToken : arg, serializeQueryArgs, context.endpointDefinitions[name], name);
|
292 | var lastValue = (0, import_react3.useRef)();
|
293 | var selectDefaultResult = (0, import_react3.useMemo)(function () { return (0, import_toolkit2.createSelector)([
|
294 | select(stableArg),
|
295 | function (_, lastResult) { return lastResult; },
|
296 | function (_) { return stableArg; }
|
297 | ], queryStatePreSelector); }, [select, stableArg]);
|
298 | var querySelector = (0, import_react3.useMemo)(function () { return selectFromResult ? (0, import_toolkit2.createSelector)([selectDefaultResult], selectFromResult) : selectDefaultResult; }, [selectDefaultResult, selectFromResult]);
|
299 | var currentState = useSelector(function (state) { return querySelector(state, lastValue.current); }, import_react_redux2.shallowEqual);
|
300 | var store = useStore();
|
301 | var newLastValue = selectDefaultResult(store.getState(), lastValue.current);
|
302 | useIsomorphicLayoutEffect(function () {
|
303 | lastValue.current = newLastValue;
|
304 | }, [newLastValue]);
|
305 | return currentState;
|
306 | };
|
307 | return {
|
308 | useQueryState: useQueryState,
|
309 | useQuerySubscription: useQuerySubscription,
|
310 | useLazyQuerySubscription: useLazyQuerySubscription,
|
311 | useLazyQuery: function (options) {
|
312 | var _c = useLazyQuerySubscription(options), trigger = _c[0], arg = _c[1];
|
313 | var queryStateResults = useQueryState(arg, __spreadProps(__spreadValues({}, options), {
|
314 | skip: arg === UNINITIALIZED_VALUE
|
315 | }));
|
316 | var info = (0, import_react3.useMemo)(function () { return ({ lastArg: arg }); }, [arg]);
|
317 | return (0, import_react3.useMemo)(function () { return [trigger, queryStateResults, info]; }, [trigger, queryStateResults, info]);
|
318 | },
|
319 | useQuery: function (arg, options) {
|
320 | var querySubscriptionResults = useQuerySubscription(arg, options);
|
321 | var queryStateResults = useQueryState(arg, __spreadValues({
|
322 | selectFromResult: arg === import_query.skipToken || (options == null ? void 0 : options.skip) ? void 0 : noPendingQueryStateSelector
|
323 | }, options));
|
324 | var data = queryStateResults.data, status = queryStateResults.status, isLoading = queryStateResults.isLoading, isSuccess = queryStateResults.isSuccess, isError = queryStateResults.isError, error = queryStateResults.error;
|
325 | (0, import_react3.useDebugValue)({ data: data, status: status, isLoading: isLoading, isSuccess: isSuccess, isError: isError, error: error });
|
326 | return (0, import_react3.useMemo)(function () { return __spreadValues(__spreadValues({}, queryStateResults), querySubscriptionResults); }, [queryStateResults, querySubscriptionResults]);
|
327 | }
|
328 | };
|
329 | }
|
330 | function buildMutationHook(name) {
|
331 | return function (_c) {
|
332 | var _d = _c === void 0 ? {} : _c, _e = _d.selectFromResult, selectFromResult = _e === void 0 ? defaultMutationStateSelector : _e, fixedCacheKey = _d.fixedCacheKey;
|
333 | var _f = api.endpoints[name], select = _f.select, initiate = _f.initiate;
|
334 | var dispatch = useDispatch();
|
335 | var _g = (0, import_react3.useState)(), promise = _g[0], setPromise = _g[1];
|
336 | (0, import_react3.useEffect)(function () { return function () {
|
337 | if (!(promise == null ? void 0 : promise.arg.fixedCacheKey)) {
|
338 | promise == null ? void 0 : promise.reset();
|
339 | }
|
340 | }; }, [promise]);
|
341 | var triggerMutation = (0, import_react3.useCallback)(function (arg) {
|
342 | var promise2 = dispatch(initiate(arg, { fixedCacheKey: fixedCacheKey }));
|
343 | setPromise(promise2);
|
344 | return promise2;
|
345 | }, [dispatch, initiate, fixedCacheKey]);
|
346 | var requestId = (promise || {}).requestId;
|
347 | var mutationSelector = (0, import_react3.useMemo)(function () { return (0, import_toolkit2.createSelector)([select({ fixedCacheKey: fixedCacheKey, requestId: promise == null ? void 0 : promise.requestId })], selectFromResult); }, [select, promise, selectFromResult, fixedCacheKey]);
|
348 | var currentState = useSelector(mutationSelector, import_react_redux2.shallowEqual);
|
349 | var originalArgs = fixedCacheKey == null ? promise == null ? void 0 : promise.arg.originalArgs : void 0;
|
350 | var reset = (0, import_react3.useCallback)(function () {
|
351 | batch(function () {
|
352 | if (promise) {
|
353 | setPromise(void 0);
|
354 | }
|
355 | if (fixedCacheKey) {
|
356 | dispatch(api.internalActions.removeMutationResult({
|
357 | requestId: requestId,
|
358 | fixedCacheKey: fixedCacheKey
|
359 | }));
|
360 | }
|
361 | });
|
362 | }, [dispatch, fixedCacheKey, promise, requestId]);
|
363 | var endpointName = currentState.endpointName, data = currentState.data, status = currentState.status, isLoading = currentState.isLoading, isSuccess = currentState.isSuccess, isError = currentState.isError, error = currentState.error;
|
364 | (0, import_react3.useDebugValue)({
|
365 | endpointName: endpointName,
|
366 | data: data,
|
367 | status: status,
|
368 | isLoading: isLoading,
|
369 | isSuccess: isSuccess,
|
370 | isError: isError,
|
371 | error: error
|
372 | });
|
373 | var finalState = (0, import_react3.useMemo)(function () { return __spreadProps(__spreadValues({}, currentState), { originalArgs: originalArgs, reset: reset }); }, [currentState, originalArgs, reset]);
|
374 | return (0, import_react3.useMemo)(function () { return [triggerMutation, finalState]; }, [triggerMutation, finalState]);
|
375 | };
|
376 | }
|
377 | }
|
378 |
|
379 | var DefinitionType;
|
380 | (function (DefinitionType2) {
|
381 | DefinitionType2["query"] = "query";
|
382 | DefinitionType2["mutation"] = "mutation";
|
383 | })(DefinitionType || (DefinitionType = {}));
|
384 | function isQueryDefinition(e) {
|
385 | return e.type === DefinitionType.query;
|
386 | }
|
387 | function isMutationDefinition(e) {
|
388 | return e.type === DefinitionType.mutation;
|
389 | }
|
390 |
|
391 | function capitalize(str) {
|
392 | return str.replace(str[0], str[0].toUpperCase());
|
393 | }
|
394 |
|
395 | function safeAssign(target) {
|
396 | var args = [];
|
397 | for (var _i = 1; _i < arguments.length; _i++) {
|
398 | args[_i - 1] = arguments[_i];
|
399 | }
|
400 | Object.assign.apply(Object, __spreadArray([target], args));
|
401 | }
|
402 |
|
403 | var import_react_redux3 = __toModule(require("react-redux"));
|
404 | var reactHooksModuleName = Symbol();
|
405 | var reactHooksModule = function (_c) {
|
406 | var _d = _c === void 0 ? {} : _c, _e = _d.batch, batch = _e === void 0 ? import_react_redux3.batch : _e, _f = _d.useDispatch, useDispatch = _f === void 0 ? import_react_redux3.useDispatch : _f, _g = _d.useSelector, useSelector = _g === void 0 ? import_react_redux3.useSelector : _g, _h = _d.useStore, useStore = _h === void 0 ? import_react_redux3.useStore : _h, _j = _d.unstable__sideEffectsInRender, unstable__sideEffectsInRender = _j === void 0 ? false : _j;
|
407 | return ({
|
408 | name: reactHooksModuleName,
|
409 | init: function (api, _c, context) {
|
410 | var serializeQueryArgs = _c.serializeQueryArgs;
|
411 | var anyApi = api;
|
412 | var _d = buildHooks({
|
413 | api: api,
|
414 | moduleOptions: {
|
415 | batch: batch,
|
416 | useDispatch: useDispatch,
|
417 | useSelector: useSelector,
|
418 | useStore: useStore,
|
419 | unstable__sideEffectsInRender: unstable__sideEffectsInRender
|
420 | },
|
421 | serializeQueryArgs: serializeQueryArgs,
|
422 | context: context
|
423 | }), buildQueryHooks = _d.buildQueryHooks, buildMutationHook = _d.buildMutationHook, usePrefetch = _d.usePrefetch;
|
424 | safeAssign(anyApi, { usePrefetch: usePrefetch });
|
425 | safeAssign(context, { batch: batch });
|
426 | return {
|
427 | injectEndpoint: function (endpointName, definition) {
|
428 | if (isQueryDefinition(definition)) {
|
429 | var _c = buildQueryHooks(endpointName), useQuery = _c.useQuery, useLazyQuery = _c.useLazyQuery, useLazyQuerySubscription = _c.useLazyQuerySubscription, useQueryState = _c.useQueryState, useQuerySubscription = _c.useQuerySubscription;
|
430 | safeAssign(anyApi.endpoints[endpointName], {
|
431 | useQuery: useQuery,
|
432 | useLazyQuery: useLazyQuery,
|
433 | useLazyQuerySubscription: useLazyQuerySubscription,
|
434 | useQueryState: useQueryState,
|
435 | useQuerySubscription: useQuerySubscription
|
436 | });
|
437 | api["use" + capitalize(endpointName) + "Query"] = useQuery;
|
438 | api["useLazy" + capitalize(endpointName) + "Query"] = useLazyQuery;
|
439 | }
|
440 | else if (isMutationDefinition(definition)) {
|
441 | var useMutation = buildMutationHook(endpointName);
|
442 | safeAssign(anyApi.endpoints[endpointName], {
|
443 | useMutation: useMutation
|
444 | });
|
445 | api["use" + capitalize(endpointName) + "Mutation"] = useMutation;
|
446 | }
|
447 | }
|
448 | };
|
449 | }
|
450 | });
|
451 | };
|
452 |
|
453 | __reExport(exports, __toModule(require("@reduxjs/toolkit/query")));
|
454 |
|
455 | var import_toolkit3 = __toModule(require("@reduxjs/toolkit"));
|
456 | var import_react4 = __toModule(require("react"));
|
457 | var import_react5 = __toModule(require("react"));
|
458 | var import_react_redux4 = __toModule(require("react-redux"));
|
459 | var import_query2 = __toModule(require("@reduxjs/toolkit/query"));
|
460 | function ApiProvider(props) {
|
461 | var store = import_react5.default.useState(function () {
|
462 | var _c;
|
463 | return (0, import_toolkit3.configureStore)({
|
464 | reducer: (_c = {},
|
465 | _c[props.api.reducerPath] = props.api.reducer,
|
466 | _c),
|
467 | middleware: function (gDM) { return gDM().concat(props.api.middleware); }
|
468 | });
|
469 | })[0];
|
470 | (0, import_react4.useEffect)(function () { return props.setupListeners === false ? void 0 : (0, import_query2.setupListeners)(store.dispatch, props.setupListeners); }, [props.setupListeners, store.dispatch]);
|
471 | return import_react5.default.createElement(import_react_redux4.Provider, {
|
472 | store: store,
|
473 | context: props.context
|
474 | }, props.children);
|
475 | }
|
476 |
|
477 | var createApi = (0, import_query3.buildCreateApi)((0, import_query3.coreModule)(), reactHooksModule());
|
478 |
|
\ | No newline at end of file |