rtk-query-react.cjs.development.js 27 KB

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