react-redux.js 78 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('react-dom')) :
  3. typeof define === 'function' && define.amd ? define(['exports', 'react', 'react-dom'], factory) :
  4. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ReactRedux = {}, global.React, global.ReactDOM));
  5. }(this, (function (exports, React, reactDom) { 'use strict';
  6. function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
  7. function _interopNamespace(e) {
  8. if (e && e.__esModule) return e;
  9. var n = Object.create(null);
  10. if (e) {
  11. Object.keys(e).forEach(function (k) {
  12. if (k !== 'default') {
  13. var d = Object.getOwnPropertyDescriptor(e, k);
  14. Object.defineProperty(n, k, d.get ? d : {
  15. enumerable: true,
  16. get: function () {
  17. return e[k];
  18. }
  19. });
  20. }
  21. });
  22. }
  23. n['default'] = e;
  24. return Object.freeze(n);
  25. }
  26. var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
  27. var React__namespace = /*#__PURE__*/_interopNamespace(React);
  28. function createCommonjsModule(fn, basedir, module) {
  29. return module = {
  30. path: basedir,
  31. exports: {},
  32. require: function (path, base) {
  33. return commonjsRequire(path, (base === undefined || base === null) ? module.path : base);
  34. }
  35. }, fn(module, module.exports), module.exports;
  36. }
  37. function commonjsRequire () {
  38. throw new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs');
  39. }
  40. var useSyncExternalStoreShim_development = createCommonjsModule(function (module, exports) {
  41. {
  42. (function() {
  43. /* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
  44. if (
  45. typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
  46. typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart ===
  47. 'function'
  48. ) {
  49. __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
  50. }
  51. var React = React__default['default'];
  52. var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
  53. function error(format) {
  54. {
  55. {
  56. for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
  57. args[_key2 - 1] = arguments[_key2];
  58. }
  59. printWarning('error', format, args);
  60. }
  61. }
  62. }
  63. function printWarning(level, format, args) {
  64. // When changing this logic, you might want to also
  65. // update consoleWithStackDev.www.js as well.
  66. {
  67. var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
  68. var stack = ReactDebugCurrentFrame.getStackAddendum();
  69. if (stack !== '') {
  70. format += '%s';
  71. args = args.concat([stack]);
  72. } // eslint-disable-next-line react-internal/safe-string-coercion
  73. var argsWithFormat = args.map(function (item) {
  74. return String(item);
  75. }); // Careful: RN currently depends on this prefix
  76. argsWithFormat.unshift('Warning: ' + format); // We intentionally don't use spread (or .apply) directly because it
  77. // breaks IE9: https://github.com/facebook/react/issues/13610
  78. // eslint-disable-next-line react-internal/no-production-logging
  79. Function.prototype.apply.call(console[level], console, argsWithFormat);
  80. }
  81. }
  82. /**
  83. * inlined Object.is polyfill to avoid requiring consumers ship their own
  84. * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
  85. */
  86. function is(x, y) {
  87. return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y // eslint-disable-line no-self-compare
  88. ;
  89. }
  90. var objectIs = typeof Object.is === 'function' ? Object.is : is;
  91. // dispatch for CommonJS interop named imports.
  92. var useState = React.useState,
  93. useEffect = React.useEffect,
  94. useLayoutEffect = React.useLayoutEffect,
  95. useDebugValue = React.useDebugValue;
  96. var didWarnOld18Alpha = false;
  97. var didWarnUncachedGetSnapshot = false; // Disclaimer: This shim breaks many of the rules of React, and only works
  98. // because of a very particular set of implementation details and assumptions
  99. // -- change any one of them and it will break. The most important assumption
  100. // is that updates are always synchronous, because concurrent rendering is
  101. // only available in versions of React that also have a built-in
  102. // useSyncExternalStore API. And we only use this shim when the built-in API
  103. // does not exist.
  104. //
  105. // Do not assume that the clever hacks used by this hook also work in general.
  106. // The point of this shim is to replace the need for hacks by other libraries.
  107. function useSyncExternalStore(subscribe, getSnapshot, // Note: The shim does not use getServerSnapshot, because pre-18 versions of
  108. // React do not expose a way to check if we're hydrating. So users of the shim
  109. // will need to track that themselves and return the correct value
  110. // from `getSnapshot`.
  111. getServerSnapshot) {
  112. {
  113. if (!didWarnOld18Alpha) {
  114. if (React.startTransition !== undefined) {
  115. didWarnOld18Alpha = true;
  116. error('You are using an outdated, pre-release alpha of React 18 that ' + 'does not support useSyncExternalStore. The ' + 'use-sync-external-store shim will not work correctly. Upgrade ' + 'to a newer pre-release.');
  117. }
  118. }
  119. } // Read the current snapshot from the store on every render. Again, this
  120. // breaks the rules of React, and only works here because of specific
  121. // implementation details, most importantly that updates are
  122. // always synchronous.
  123. var value = getSnapshot();
  124. {
  125. if (!didWarnUncachedGetSnapshot) {
  126. var cachedValue = getSnapshot();
  127. if (!objectIs(value, cachedValue)) {
  128. error('The result of getSnapshot should be cached to avoid an infinite loop');
  129. didWarnUncachedGetSnapshot = true;
  130. }
  131. }
  132. } // Because updates are synchronous, we don't queue them. Instead we force a
  133. // re-render whenever the subscribed state changes by updating an some
  134. // arbitrary useState hook. Then, during render, we call getSnapshot to read
  135. // the current value.
  136. //
  137. // Because we don't actually use the state returned by the useState hook, we
  138. // can save a bit of memory by storing other stuff in that slot.
  139. //
  140. // To implement the early bailout, we need to track some things on a mutable
  141. // object. Usually, we would put that in a useRef hook, but we can stash it in
  142. // our useState hook instead.
  143. //
  144. // To force a re-render, we call forceUpdate({inst}). That works because the
  145. // new object always fails an equality check.
  146. var _useState = useState({
  147. inst: {
  148. value: value,
  149. getSnapshot: getSnapshot
  150. }
  151. }),
  152. inst = _useState[0].inst,
  153. forceUpdate = _useState[1]; // Track the latest getSnapshot function with a ref. This needs to be updated
  154. // in the layout phase so we can access it during the tearing check that
  155. // happens on subscribe.
  156. useLayoutEffect(function () {
  157. inst.value = value;
  158. inst.getSnapshot = getSnapshot; // Whenever getSnapshot or subscribe changes, we need to check in the
  159. // commit phase if there was an interleaved mutation. In concurrent mode
  160. // this can happen all the time, but even in synchronous mode, an earlier
  161. // effect may have mutated the store.
  162. if (checkIfSnapshotChanged(inst)) {
  163. // Force a re-render.
  164. forceUpdate({
  165. inst: inst
  166. });
  167. }
  168. }, [subscribe, value, getSnapshot]);
  169. useEffect(function () {
  170. // Check for changes right before subscribing. Subsequent changes will be
  171. // detected in the subscription handler.
  172. if (checkIfSnapshotChanged(inst)) {
  173. // Force a re-render.
  174. forceUpdate({
  175. inst: inst
  176. });
  177. }
  178. var handleStoreChange = function () {
  179. // TODO: Because there is no cross-renderer API for batching updates, it's
  180. // up to the consumer of this library to wrap their subscription event
  181. // with unstable_batchedUpdates. Should we try to detect when this isn't
  182. // the case and print a warning in development?
  183. // The store changed. Check if the snapshot changed since the last time we
  184. // read from the store.
  185. if (checkIfSnapshotChanged(inst)) {
  186. // Force a re-render.
  187. forceUpdate({
  188. inst: inst
  189. });
  190. }
  191. }; // Subscribe to the store and return a clean-up function.
  192. return subscribe(handleStoreChange);
  193. }, [subscribe]);
  194. useDebugValue(value);
  195. return value;
  196. }
  197. function checkIfSnapshotChanged(inst) {
  198. var latestGetSnapshot = inst.getSnapshot;
  199. var prevValue = inst.value;
  200. try {
  201. var nextValue = latestGetSnapshot();
  202. return !objectIs(prevValue, nextValue);
  203. } catch (error) {
  204. return true;
  205. }
  206. }
  207. function useSyncExternalStore$1(subscribe, getSnapshot, getServerSnapshot) {
  208. // Note: The shim does not use getServerSnapshot, because pre-18 versions of
  209. // React do not expose a way to check if we're hydrating. So users of the shim
  210. // will need to track that themselves and return the correct value
  211. // from `getSnapshot`.
  212. return getSnapshot();
  213. }
  214. var canUseDOM = !!(typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined');
  215. var isServerEnvironment = !canUseDOM;
  216. var shim = isServerEnvironment ? useSyncExternalStore$1 : useSyncExternalStore;
  217. var useSyncExternalStore$2 = React.useSyncExternalStore !== undefined ? React.useSyncExternalStore : shim;
  218. exports.useSyncExternalStore = useSyncExternalStore$2;
  219. /* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
  220. if (
  221. typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
  222. typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop ===
  223. 'function'
  224. ) {
  225. __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());
  226. }
  227. })();
  228. }
  229. });
  230. var shim = createCommonjsModule(function (module) {
  231. {
  232. module.exports = useSyncExternalStoreShim_development;
  233. }
  234. });
  235. var withSelector_development = createCommonjsModule(function (module, exports) {
  236. {
  237. (function() {
  238. /* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
  239. if (
  240. typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
  241. typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart ===
  242. 'function'
  243. ) {
  244. __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
  245. }
  246. var React = React__default['default'];
  247. var shim$1 = shim;
  248. /**
  249. * inlined Object.is polyfill to avoid requiring consumers ship their own
  250. * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
  251. */
  252. function is(x, y) {
  253. return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y // eslint-disable-line no-self-compare
  254. ;
  255. }
  256. var objectIs = typeof Object.is === 'function' ? Object.is : is;
  257. var useSyncExternalStore = shim$1.useSyncExternalStore;
  258. // for CommonJS interop.
  259. var useRef = React.useRef,
  260. useEffect = React.useEffect,
  261. useMemo = React.useMemo,
  262. useDebugValue = React.useDebugValue; // Same as useSyncExternalStore, but supports selector and isEqual arguments.
  263. function useSyncExternalStoreWithSelector(subscribe, getSnapshot, getServerSnapshot, selector, isEqual) {
  264. // Use this to track the rendered snapshot.
  265. var instRef = useRef(null);
  266. var inst;
  267. if (instRef.current === null) {
  268. inst = {
  269. hasValue: false,
  270. value: null
  271. };
  272. instRef.current = inst;
  273. } else {
  274. inst = instRef.current;
  275. }
  276. var _useMemo = useMemo(function () {
  277. // Track the memoized state using closure variables that are local to this
  278. // memoized instance of a getSnapshot function. Intentionally not using a
  279. // useRef hook, because that state would be shared across all concurrent
  280. // copies of the hook/component.
  281. var hasMemo = false;
  282. var memoizedSnapshot;
  283. var memoizedSelection;
  284. var memoizedSelector = function (nextSnapshot) {
  285. if (!hasMemo) {
  286. // The first time the hook is called, there is no memoized result.
  287. hasMemo = true;
  288. memoizedSnapshot = nextSnapshot;
  289. var _nextSelection = selector(nextSnapshot);
  290. if (isEqual !== undefined) {
  291. // Even if the selector has changed, the currently rendered selection
  292. // may be equal to the new selection. We should attempt to reuse the
  293. // current value if possible, to preserve downstream memoizations.
  294. if (inst.hasValue) {
  295. var currentSelection = inst.value;
  296. if (isEqual(currentSelection, _nextSelection)) {
  297. memoizedSelection = currentSelection;
  298. return currentSelection;
  299. }
  300. }
  301. }
  302. memoizedSelection = _nextSelection;
  303. return _nextSelection;
  304. } // We may be able to reuse the previous invocation's result.
  305. //console.log("Memoized selector: ", {memoizedSnapshot, nextSnapshot, identical: memoizedSnapshot === nextSnapshot});
  306. // We may be able to reuse the previous invocation's result.
  307. var prevSnapshot = memoizedSnapshot;
  308. var prevSelection = memoizedSelection;
  309. if (objectIs(prevSnapshot, nextSnapshot)) {
  310. // The snapshot is the same as last time. Reuse the previous selection.
  311. return prevSelection;
  312. } // The snapshot has changed, so we need to compute a new selection.
  313. // The snapshot has changed, so we need to compute a new selection.
  314. var nextSelection = selector(nextSnapshot); // If a custom isEqual function is provided, use that to check if the data
  315. // has changed. If it hasn't, return the previous selection. That signals
  316. // to React that the selections are conceptually equal, and we can bail
  317. // out of rendering.
  318. // If a custom isEqual function is provided, use that to check if the data
  319. // has changed. If it hasn't, return the previous selection. That signals
  320. // to React that the selections are conceptually equal, and we can bail
  321. // out of rendering.
  322. //console.log("Selections: ", {prevSelection, nextSelection, equal: prevSelection === nextSelection})
  323. if (isEqual !== undefined && isEqual(prevSelection, nextSelection)) {
  324. return prevSelection;
  325. }
  326. memoizedSnapshot = nextSnapshot;
  327. memoizedSelection = nextSelection;
  328. return nextSelection;
  329. }; // Assigning this to a constant so that Flow knows it can't change.
  330. // Assigning this to a constant so that Flow knows it can't change.
  331. var maybeGetServerSnapshot = getServerSnapshot === undefined ? null : getServerSnapshot;
  332. var getSnapshotWithSelector = function () {
  333. //console.log("getSnapshotWithSelector")
  334. return memoizedSelector(getSnapshot());
  335. };
  336. var getServerSnapshotWithSelector = maybeGetServerSnapshot === null ? undefined : function () {
  337. return memoizedSelector(maybeGetServerSnapshot());
  338. };
  339. return [getSnapshotWithSelector, getServerSnapshotWithSelector];
  340. }, [getSnapshot, getServerSnapshot, selector, isEqual]),
  341. getSelection = _useMemo[0],
  342. getServerSelection = _useMemo[1];
  343. var value = useSyncExternalStore(subscribe, getSelection, getServerSelection);
  344. useEffect(function () {
  345. inst.hasValue = true;
  346. inst.value = value;
  347. }, [value]);
  348. useDebugValue(value);
  349. return value;
  350. }
  351. exports.useSyncExternalStoreWithSelector = useSyncExternalStoreWithSelector;
  352. /* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
  353. if (
  354. typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
  355. typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop ===
  356. 'function'
  357. ) {
  358. __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());
  359. }
  360. })();
  361. }
  362. });
  363. var withSelector = createCommonjsModule(function (module) {
  364. {
  365. module.exports = withSelector_development;
  366. }
  367. });
  368. // Default to a dummy "batch" implementation that just runs the callback
  369. function defaultNoopBatch(callback) {
  370. callback();
  371. }
  372. let batch = defaultNoopBatch; // Allow injecting another batching function later
  373. const setBatch = newBatch => batch = newBatch; // Supply a getter just to skip dealing with ESM bindings
  374. const getBatch = () => batch;
  375. const ContextKey = Symbol.for(`react-redux-context`);
  376. const gT = typeof globalThis !== "undefined" ? globalThis :
  377. /* fall back to a per-module scope (pre-8.1 behaviour) if `globalThis` is not available */
  378. {};
  379. function getContext() {
  380. var _gT$ContextKey;
  381. if (!React__namespace.createContext) return {};
  382. const contextMap = (_gT$ContextKey = gT[ContextKey]) != null ? _gT$ContextKey : gT[ContextKey] = new Map();
  383. let realContext = contextMap.get(React__namespace.createContext);
  384. if (!realContext) {
  385. realContext = React__namespace.createContext(null);
  386. {
  387. realContext.displayName = 'ReactRedux';
  388. }
  389. contextMap.set(React__namespace.createContext, realContext);
  390. }
  391. return realContext;
  392. }
  393. const ReactReduxContext = /*#__PURE__*/getContext();
  394. /**
  395. * Hook factory, which creates a `useReduxContext` hook bound to a given context. This is a low-level
  396. * hook that you should usually not need to call directly.
  397. *
  398. * @param {React.Context} [context=ReactReduxContext] Context passed to your `<Provider>`.
  399. * @returns {Function} A `useReduxContext` hook bound to the specified context.
  400. */
  401. function createReduxContextHook(context = ReactReduxContext) {
  402. return function useReduxContext() {
  403. const contextValue = React.useContext(context);
  404. if (!contextValue) {
  405. throw new Error('could not find react-redux context value; please ensure the component is wrapped in a <Provider>');
  406. }
  407. return contextValue;
  408. };
  409. }
  410. /**
  411. * A hook to access the value of the `ReactReduxContext`. This is a low-level
  412. * hook that you should usually not need to call directly.
  413. *
  414. * @returns {any} the value of the `ReactReduxContext`
  415. *
  416. * @example
  417. *
  418. * import React from 'react'
  419. * import { useReduxContext } from 'react-redux'
  420. *
  421. * export const CounterComponent = () => {
  422. * const { store } = useReduxContext()
  423. * return <div>{store.getState()}</div>
  424. * }
  425. */
  426. const useReduxContext = /*#__PURE__*/createReduxContextHook();
  427. const notInitialized = () => {
  428. throw new Error('uSES not initialized!');
  429. };
  430. let useSyncExternalStoreWithSelector = notInitialized;
  431. const initializeUseSelector = fn => {
  432. useSyncExternalStoreWithSelector = fn;
  433. };
  434. const refEquality = (a, b) => a === b;
  435. /**
  436. * Hook factory, which creates a `useSelector` hook bound to a given context.
  437. *
  438. * @param {React.Context} [context=ReactReduxContext] Context passed to your `<Provider>`.
  439. * @returns {Function} A `useSelector` hook bound to the specified context.
  440. */
  441. function createSelectorHook(context = ReactReduxContext) {
  442. const useReduxContext$1 = context === ReactReduxContext ? useReduxContext : createReduxContextHook(context);
  443. return function useSelector(selector, equalityFnOrOptions = {}) {
  444. const {
  445. equalityFn = refEquality,
  446. stabilityCheck = undefined,
  447. noopCheck = undefined
  448. } = typeof equalityFnOrOptions === 'function' ? {
  449. equalityFn: equalityFnOrOptions
  450. } : equalityFnOrOptions;
  451. {
  452. if (!selector) {
  453. throw new Error(`You must pass a selector to useSelector`);
  454. }
  455. if (typeof selector !== 'function') {
  456. throw new Error(`You must pass a function as a selector to useSelector`);
  457. }
  458. if (typeof equalityFn !== 'function') {
  459. throw new Error(`You must pass a function as an equality function to useSelector`);
  460. }
  461. }
  462. const {
  463. store,
  464. subscription,
  465. getServerState,
  466. stabilityCheck: globalStabilityCheck,
  467. noopCheck: globalNoopCheck
  468. } = useReduxContext$1();
  469. const firstRun = React.useRef(true);
  470. const wrappedSelector = React.useCallback({
  471. [selector.name](state) {
  472. const selected = selector(state);
  473. {
  474. const finalStabilityCheck = typeof stabilityCheck === 'undefined' ? globalStabilityCheck : stabilityCheck;
  475. if (finalStabilityCheck === 'always' || finalStabilityCheck === 'once' && firstRun.current) {
  476. const toCompare = selector(state);
  477. if (!equalityFn(selected, toCompare)) {
  478. let stack = undefined;
  479. try {
  480. throw new Error();
  481. } catch (e) {
  482. ({
  483. stack
  484. } = e);
  485. }
  486. console.warn('Selector ' + (selector.name || 'unknown') + ' returned a different result when called with the same parameters. This can lead to unnecessary rerenders.' + '\nSelectors that return a new reference (such as an object or an array) should be memoized: https://redux.js.org/usage/deriving-data-selectors#optimizing-selectors-with-memoization', {
  487. state,
  488. selected,
  489. selected2: toCompare,
  490. stack
  491. });
  492. }
  493. }
  494. const finalNoopCheck = typeof noopCheck === 'undefined' ? globalNoopCheck : noopCheck;
  495. if (finalNoopCheck === 'always' || finalNoopCheck === 'once' && firstRun.current) {
  496. // @ts-ignore
  497. if (selected === state) {
  498. let stack = undefined;
  499. try {
  500. throw new Error();
  501. } catch (e) {
  502. ({
  503. stack
  504. } = e);
  505. }
  506. console.warn('Selector ' + (selector.name || 'unknown') + ' returned the root state when called. This can lead to unnecessary rerenders.' + '\nSelectors that return the entire state are almost certainly a mistake, as they will cause a rerender whenever *anything* in state changes.', {
  507. stack
  508. });
  509. }
  510. }
  511. if (firstRun.current) firstRun.current = false;
  512. }
  513. return selected;
  514. }
  515. }[selector.name], [selector, globalStabilityCheck, stabilityCheck]);
  516. const selectedState = useSyncExternalStoreWithSelector(subscription.addNestedSub, store.getState, getServerState || store.getState, wrappedSelector, equalityFn);
  517. React.useDebugValue(selectedState);
  518. return selectedState;
  519. };
  520. }
  521. /**
  522. * A hook to access the redux store's state. This hook takes a selector function
  523. * as an argument. The selector is called with the store state.
  524. *
  525. * This hook takes an optional equality comparison function as the second parameter
  526. * that allows you to customize the way the selected state is compared to determine
  527. * whether the component needs to be re-rendered.
  528. *
  529. * @param {Function} selector the selector function
  530. * @param {Function=} equalityFn the function that will be used to determine equality
  531. *
  532. * @returns {any} the selected state
  533. *
  534. * @example
  535. *
  536. * import React from 'react'
  537. * import { useSelector } from 'react-redux'
  538. *
  539. * export const CounterComponent = () => {
  540. * const counter = useSelector(state => state.counter)
  541. * return <div>{counter}</div>
  542. * }
  543. */
  544. const useSelector = /*#__PURE__*/createSelectorHook();
  545. function _extends() {
  546. _extends = Object.assign || function (target) {
  547. for (var i = 1; i < arguments.length; i++) {
  548. var source = arguments[i];
  549. for (var key in source) {
  550. if (Object.prototype.hasOwnProperty.call(source, key)) {
  551. target[key] = source[key];
  552. }
  553. }
  554. }
  555. return target;
  556. };
  557. return _extends.apply(this, arguments);
  558. }
  559. function _objectWithoutPropertiesLoose(source, excluded) {
  560. if (source == null) return {};
  561. var target = {};
  562. var sourceKeys = Object.keys(source);
  563. var key, i;
  564. for (i = 0; i < sourceKeys.length; i++) {
  565. key = sourceKeys[i];
  566. if (excluded.indexOf(key) >= 0) continue;
  567. target[key] = source[key];
  568. }
  569. return target;
  570. }
  571. var reactIs_development$1 = createCommonjsModule(function (module, exports) {
  572. {
  573. (function() {
  574. // The Symbol used to tag the ReactElement-like types. If there is no native Symbol
  575. // nor polyfill, then a plain number is used for performance.
  576. var hasSymbol = typeof Symbol === 'function' && Symbol.for;
  577. var REACT_ELEMENT_TYPE = hasSymbol ? Symbol.for('react.element') : 0xeac7;
  578. var REACT_PORTAL_TYPE = hasSymbol ? Symbol.for('react.portal') : 0xeaca;
  579. var REACT_FRAGMENT_TYPE = hasSymbol ? Symbol.for('react.fragment') : 0xeacb;
  580. var REACT_STRICT_MODE_TYPE = hasSymbol ? Symbol.for('react.strict_mode') : 0xeacc;
  581. var REACT_PROFILER_TYPE = hasSymbol ? Symbol.for('react.profiler') : 0xead2;
  582. var REACT_PROVIDER_TYPE = hasSymbol ? Symbol.for('react.provider') : 0xeacd;
  583. var REACT_CONTEXT_TYPE = hasSymbol ? Symbol.for('react.context') : 0xeace; // TODO: We don't use AsyncMode or ConcurrentMode anymore. They were temporary
  584. // (unstable) APIs that have been removed. Can we remove the symbols?
  585. var REACT_ASYNC_MODE_TYPE = hasSymbol ? Symbol.for('react.async_mode') : 0xeacf;
  586. var REACT_CONCURRENT_MODE_TYPE = hasSymbol ? Symbol.for('react.concurrent_mode') : 0xeacf;
  587. var REACT_FORWARD_REF_TYPE = hasSymbol ? Symbol.for('react.forward_ref') : 0xead0;
  588. var REACT_SUSPENSE_TYPE = hasSymbol ? Symbol.for('react.suspense') : 0xead1;
  589. var REACT_SUSPENSE_LIST_TYPE = hasSymbol ? Symbol.for('react.suspense_list') : 0xead8;
  590. var REACT_MEMO_TYPE = hasSymbol ? Symbol.for('react.memo') : 0xead3;
  591. var REACT_LAZY_TYPE = hasSymbol ? Symbol.for('react.lazy') : 0xead4;
  592. var REACT_BLOCK_TYPE = hasSymbol ? Symbol.for('react.block') : 0xead9;
  593. var REACT_FUNDAMENTAL_TYPE = hasSymbol ? Symbol.for('react.fundamental') : 0xead5;
  594. var REACT_RESPONDER_TYPE = hasSymbol ? Symbol.for('react.responder') : 0xead6;
  595. var REACT_SCOPE_TYPE = hasSymbol ? Symbol.for('react.scope') : 0xead7;
  596. function isValidElementType(type) {
  597. return typeof type === 'string' || typeof type === 'function' || // Note: its typeof might be other than 'symbol' or 'number' if it's a polyfill.
  598. type === REACT_FRAGMENT_TYPE || type === REACT_CONCURRENT_MODE_TYPE || type === REACT_PROFILER_TYPE || type === REACT_STRICT_MODE_TYPE || type === REACT_SUSPENSE_TYPE || type === REACT_SUSPENSE_LIST_TYPE || typeof type === 'object' && type !== null && (type.$$typeof === REACT_LAZY_TYPE || type.$$typeof === REACT_MEMO_TYPE || type.$$typeof === REACT_PROVIDER_TYPE || type.$$typeof === REACT_CONTEXT_TYPE || type.$$typeof === REACT_FORWARD_REF_TYPE || type.$$typeof === REACT_FUNDAMENTAL_TYPE || type.$$typeof === REACT_RESPONDER_TYPE || type.$$typeof === REACT_SCOPE_TYPE || type.$$typeof === REACT_BLOCK_TYPE);
  599. }
  600. function typeOf(object) {
  601. if (typeof object === 'object' && object !== null) {
  602. var $$typeof = object.$$typeof;
  603. switch ($$typeof) {
  604. case REACT_ELEMENT_TYPE:
  605. var type = object.type;
  606. switch (type) {
  607. case REACT_ASYNC_MODE_TYPE:
  608. case REACT_CONCURRENT_MODE_TYPE:
  609. case REACT_FRAGMENT_TYPE:
  610. case REACT_PROFILER_TYPE:
  611. case REACT_STRICT_MODE_TYPE:
  612. case REACT_SUSPENSE_TYPE:
  613. return type;
  614. default:
  615. var $$typeofType = type && type.$$typeof;
  616. switch ($$typeofType) {
  617. case REACT_CONTEXT_TYPE:
  618. case REACT_FORWARD_REF_TYPE:
  619. case REACT_LAZY_TYPE:
  620. case REACT_MEMO_TYPE:
  621. case REACT_PROVIDER_TYPE:
  622. return $$typeofType;
  623. default:
  624. return $$typeof;
  625. }
  626. }
  627. case REACT_PORTAL_TYPE:
  628. return $$typeof;
  629. }
  630. }
  631. return undefined;
  632. } // AsyncMode is deprecated along with isAsyncMode
  633. var AsyncMode = REACT_ASYNC_MODE_TYPE;
  634. var ConcurrentMode = REACT_CONCURRENT_MODE_TYPE;
  635. var ContextConsumer = REACT_CONTEXT_TYPE;
  636. var ContextProvider = REACT_PROVIDER_TYPE;
  637. var Element = REACT_ELEMENT_TYPE;
  638. var ForwardRef = REACT_FORWARD_REF_TYPE;
  639. var Fragment = REACT_FRAGMENT_TYPE;
  640. var Lazy = REACT_LAZY_TYPE;
  641. var Memo = REACT_MEMO_TYPE;
  642. var Portal = REACT_PORTAL_TYPE;
  643. var Profiler = REACT_PROFILER_TYPE;
  644. var StrictMode = REACT_STRICT_MODE_TYPE;
  645. var Suspense = REACT_SUSPENSE_TYPE;
  646. var hasWarnedAboutDeprecatedIsAsyncMode = false; // AsyncMode should be deprecated
  647. function isAsyncMode(object) {
  648. {
  649. if (!hasWarnedAboutDeprecatedIsAsyncMode) {
  650. hasWarnedAboutDeprecatedIsAsyncMode = true; // Using console['warn'] to evade Babel and ESLint
  651. console['warn']('The ReactIs.isAsyncMode() alias has been deprecated, ' + 'and will be removed in React 17+. Update your code to use ' + 'ReactIs.isConcurrentMode() instead. It has the exact same API.');
  652. }
  653. }
  654. return isConcurrentMode(object) || typeOf(object) === REACT_ASYNC_MODE_TYPE;
  655. }
  656. function isConcurrentMode(object) {
  657. return typeOf(object) === REACT_CONCURRENT_MODE_TYPE;
  658. }
  659. function isContextConsumer(object) {
  660. return typeOf(object) === REACT_CONTEXT_TYPE;
  661. }
  662. function isContextProvider(object) {
  663. return typeOf(object) === REACT_PROVIDER_TYPE;
  664. }
  665. function isElement(object) {
  666. return typeof object === 'object' && object !== null && object.$$typeof === REACT_ELEMENT_TYPE;
  667. }
  668. function isForwardRef(object) {
  669. return typeOf(object) === REACT_FORWARD_REF_TYPE;
  670. }
  671. function isFragment(object) {
  672. return typeOf(object) === REACT_FRAGMENT_TYPE;
  673. }
  674. function isLazy(object) {
  675. return typeOf(object) === REACT_LAZY_TYPE;
  676. }
  677. function isMemo(object) {
  678. return typeOf(object) === REACT_MEMO_TYPE;
  679. }
  680. function isPortal(object) {
  681. return typeOf(object) === REACT_PORTAL_TYPE;
  682. }
  683. function isProfiler(object) {
  684. return typeOf(object) === REACT_PROFILER_TYPE;
  685. }
  686. function isStrictMode(object) {
  687. return typeOf(object) === REACT_STRICT_MODE_TYPE;
  688. }
  689. function isSuspense(object) {
  690. return typeOf(object) === REACT_SUSPENSE_TYPE;
  691. }
  692. exports.AsyncMode = AsyncMode;
  693. exports.ConcurrentMode = ConcurrentMode;
  694. exports.ContextConsumer = ContextConsumer;
  695. exports.ContextProvider = ContextProvider;
  696. exports.Element = Element;
  697. exports.ForwardRef = ForwardRef;
  698. exports.Fragment = Fragment;
  699. exports.Lazy = Lazy;
  700. exports.Memo = Memo;
  701. exports.Portal = Portal;
  702. exports.Profiler = Profiler;
  703. exports.StrictMode = StrictMode;
  704. exports.Suspense = Suspense;
  705. exports.isAsyncMode = isAsyncMode;
  706. exports.isConcurrentMode = isConcurrentMode;
  707. exports.isContextConsumer = isContextConsumer;
  708. exports.isContextProvider = isContextProvider;
  709. exports.isElement = isElement;
  710. exports.isForwardRef = isForwardRef;
  711. exports.isFragment = isFragment;
  712. exports.isLazy = isLazy;
  713. exports.isMemo = isMemo;
  714. exports.isPortal = isPortal;
  715. exports.isProfiler = isProfiler;
  716. exports.isStrictMode = isStrictMode;
  717. exports.isSuspense = isSuspense;
  718. exports.isValidElementType = isValidElementType;
  719. exports.typeOf = typeOf;
  720. })();
  721. }
  722. });
  723. var reactIs$1 = createCommonjsModule(function (module) {
  724. {
  725. module.exports = reactIs_development$1;
  726. }
  727. });
  728. /**
  729. * Copyright 2015, Yahoo! Inc.
  730. * Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms.
  731. */
  732. var REACT_STATICS = {
  733. childContextTypes: true,
  734. contextType: true,
  735. contextTypes: true,
  736. defaultProps: true,
  737. displayName: true,
  738. getDefaultProps: true,
  739. getDerivedStateFromError: true,
  740. getDerivedStateFromProps: true,
  741. mixins: true,
  742. propTypes: true,
  743. type: true
  744. };
  745. var KNOWN_STATICS = {
  746. name: true,
  747. length: true,
  748. prototype: true,
  749. caller: true,
  750. callee: true,
  751. arguments: true,
  752. arity: true
  753. };
  754. var FORWARD_REF_STATICS = {
  755. '$$typeof': true,
  756. render: true,
  757. defaultProps: true,
  758. displayName: true,
  759. propTypes: true
  760. };
  761. var MEMO_STATICS = {
  762. '$$typeof': true,
  763. compare: true,
  764. defaultProps: true,
  765. displayName: true,
  766. propTypes: true,
  767. type: true
  768. };
  769. var TYPE_STATICS = {};
  770. TYPE_STATICS[reactIs$1.ForwardRef] = FORWARD_REF_STATICS;
  771. TYPE_STATICS[reactIs$1.Memo] = MEMO_STATICS;
  772. function getStatics(component) {
  773. // React v16.11 and below
  774. if (reactIs$1.isMemo(component)) {
  775. return MEMO_STATICS;
  776. } // React v16.12 and above
  777. return TYPE_STATICS[component['$$typeof']] || REACT_STATICS;
  778. }
  779. var defineProperty = Object.defineProperty;
  780. var getOwnPropertyNames = Object.getOwnPropertyNames;
  781. var getOwnPropertySymbols = Object.getOwnPropertySymbols;
  782. var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
  783. var getPrototypeOf = Object.getPrototypeOf;
  784. var objectPrototype = Object.prototype;
  785. function hoistNonReactStatics(targetComponent, sourceComponent, blacklist) {
  786. if (typeof sourceComponent !== 'string') {
  787. // don't hoist over string (html) components
  788. if (objectPrototype) {
  789. var inheritedComponent = getPrototypeOf(sourceComponent);
  790. if (inheritedComponent && inheritedComponent !== objectPrototype) {
  791. hoistNonReactStatics(targetComponent, inheritedComponent, blacklist);
  792. }
  793. }
  794. var keys = getOwnPropertyNames(sourceComponent);
  795. if (getOwnPropertySymbols) {
  796. keys = keys.concat(getOwnPropertySymbols(sourceComponent));
  797. }
  798. var targetStatics = getStatics(targetComponent);
  799. var sourceStatics = getStatics(sourceComponent);
  800. for (var i = 0; i < keys.length; ++i) {
  801. var key = keys[i];
  802. if (!KNOWN_STATICS[key] && !(blacklist && blacklist[key]) && !(sourceStatics && sourceStatics[key]) && !(targetStatics && targetStatics[key])) {
  803. var descriptor = getOwnPropertyDescriptor(sourceComponent, key);
  804. try {
  805. // Avoid failures from read-only properties
  806. defineProperty(targetComponent, key, descriptor);
  807. } catch (e) {}
  808. }
  809. }
  810. }
  811. return targetComponent;
  812. }
  813. var hoistNonReactStatics_cjs = hoistNonReactStatics;
  814. var reactIs_development = createCommonjsModule(function (module, exports) {
  815. {
  816. (function() {
  817. // ATTENTION
  818. // When adding new symbols to this file,
  819. // Please consider also adding to 'react-devtools-shared/src/backend/ReactSymbols'
  820. // The Symbol used to tag the ReactElement-like types.
  821. var REACT_ELEMENT_TYPE = Symbol.for('react.element');
  822. var REACT_PORTAL_TYPE = Symbol.for('react.portal');
  823. var REACT_FRAGMENT_TYPE = Symbol.for('react.fragment');
  824. var REACT_STRICT_MODE_TYPE = Symbol.for('react.strict_mode');
  825. var REACT_PROFILER_TYPE = Symbol.for('react.profiler');
  826. var REACT_PROVIDER_TYPE = Symbol.for('react.provider');
  827. var REACT_CONTEXT_TYPE = Symbol.for('react.context');
  828. var REACT_SERVER_CONTEXT_TYPE = Symbol.for('react.server_context');
  829. var REACT_FORWARD_REF_TYPE = Symbol.for('react.forward_ref');
  830. var REACT_SUSPENSE_TYPE = Symbol.for('react.suspense');
  831. var REACT_SUSPENSE_LIST_TYPE = Symbol.for('react.suspense_list');
  832. var REACT_MEMO_TYPE = Symbol.for('react.memo');
  833. var REACT_LAZY_TYPE = Symbol.for('react.lazy');
  834. var REACT_OFFSCREEN_TYPE = Symbol.for('react.offscreen');
  835. // -----------------------------------------------------------------------------
  836. var enableScopeAPI = false; // Experimental Create Event Handle API.
  837. var enableCacheElement = false;
  838. var enableTransitionTracing = false; // No known bugs, but needs performance testing
  839. var enableLegacyHidden = false; // Enables unstable_avoidThisFallback feature in Fiber
  840. // stuff. Intended to enable React core members to more easily debug scheduling
  841. // issues in DEV builds.
  842. var enableDebugTracing = false; // Track which Fiber(s) schedule render work.
  843. var REACT_MODULE_REFERENCE = Symbol.for('react.module.reference');
  844. function isValidElementType(type) {
  845. if (typeof type === 'string' || typeof type === 'function') {
  846. return true;
  847. } // Note: typeof might be other than 'symbol' or 'number' (e.g. if it's a polyfill).
  848. if (type === REACT_FRAGMENT_TYPE || type === REACT_PROFILER_TYPE || enableDebugTracing || type === REACT_STRICT_MODE_TYPE || type === REACT_SUSPENSE_TYPE || type === REACT_SUSPENSE_LIST_TYPE || enableLegacyHidden || type === REACT_OFFSCREEN_TYPE || enableScopeAPI || enableCacheElement || enableTransitionTracing ) {
  849. return true;
  850. }
  851. if (typeof type === 'object' && type !== null) {
  852. if (type.$$typeof === REACT_LAZY_TYPE || type.$$typeof === REACT_MEMO_TYPE || type.$$typeof === REACT_PROVIDER_TYPE || type.$$typeof === REACT_CONTEXT_TYPE || type.$$typeof === REACT_FORWARD_REF_TYPE || // This needs to include all possible module reference object
  853. // types supported by any Flight configuration anywhere since
  854. // we don't know which Flight build this will end up being used
  855. // with.
  856. type.$$typeof === REACT_MODULE_REFERENCE || type.getModuleId !== undefined) {
  857. return true;
  858. }
  859. }
  860. return false;
  861. }
  862. function typeOf(object) {
  863. if (typeof object === 'object' && object !== null) {
  864. var $$typeof = object.$$typeof;
  865. switch ($$typeof) {
  866. case REACT_ELEMENT_TYPE:
  867. var type = object.type;
  868. switch (type) {
  869. case REACT_FRAGMENT_TYPE:
  870. case REACT_PROFILER_TYPE:
  871. case REACT_STRICT_MODE_TYPE:
  872. case REACT_SUSPENSE_TYPE:
  873. case REACT_SUSPENSE_LIST_TYPE:
  874. return type;
  875. default:
  876. var $$typeofType = type && type.$$typeof;
  877. switch ($$typeofType) {
  878. case REACT_SERVER_CONTEXT_TYPE:
  879. case REACT_CONTEXT_TYPE:
  880. case REACT_FORWARD_REF_TYPE:
  881. case REACT_LAZY_TYPE:
  882. case REACT_MEMO_TYPE:
  883. case REACT_PROVIDER_TYPE:
  884. return $$typeofType;
  885. default:
  886. return $$typeof;
  887. }
  888. }
  889. case REACT_PORTAL_TYPE:
  890. return $$typeof;
  891. }
  892. }
  893. return undefined;
  894. }
  895. var ContextConsumer = REACT_CONTEXT_TYPE;
  896. var ContextProvider = REACT_PROVIDER_TYPE;
  897. var Element = REACT_ELEMENT_TYPE;
  898. var ForwardRef = REACT_FORWARD_REF_TYPE;
  899. var Fragment = REACT_FRAGMENT_TYPE;
  900. var Lazy = REACT_LAZY_TYPE;
  901. var Memo = REACT_MEMO_TYPE;
  902. var Portal = REACT_PORTAL_TYPE;
  903. var Profiler = REACT_PROFILER_TYPE;
  904. var StrictMode = REACT_STRICT_MODE_TYPE;
  905. var Suspense = REACT_SUSPENSE_TYPE;
  906. var SuspenseList = REACT_SUSPENSE_LIST_TYPE;
  907. var hasWarnedAboutDeprecatedIsAsyncMode = false;
  908. var hasWarnedAboutDeprecatedIsConcurrentMode = false; // AsyncMode should be deprecated
  909. function isAsyncMode(object) {
  910. {
  911. if (!hasWarnedAboutDeprecatedIsAsyncMode) {
  912. hasWarnedAboutDeprecatedIsAsyncMode = true; // Using console['warn'] to evade Babel and ESLint
  913. console['warn']('The ReactIs.isAsyncMode() alias has been deprecated, ' + 'and will be removed in React 18+.');
  914. }
  915. }
  916. return false;
  917. }
  918. function isConcurrentMode(object) {
  919. {
  920. if (!hasWarnedAboutDeprecatedIsConcurrentMode) {
  921. hasWarnedAboutDeprecatedIsConcurrentMode = true; // Using console['warn'] to evade Babel and ESLint
  922. console['warn']('The ReactIs.isConcurrentMode() alias has been deprecated, ' + 'and will be removed in React 18+.');
  923. }
  924. }
  925. return false;
  926. }
  927. function isContextConsumer(object) {
  928. return typeOf(object) === REACT_CONTEXT_TYPE;
  929. }
  930. function isContextProvider(object) {
  931. return typeOf(object) === REACT_PROVIDER_TYPE;
  932. }
  933. function isElement(object) {
  934. return typeof object === 'object' && object !== null && object.$$typeof === REACT_ELEMENT_TYPE;
  935. }
  936. function isForwardRef(object) {
  937. return typeOf(object) === REACT_FORWARD_REF_TYPE;
  938. }
  939. function isFragment(object) {
  940. return typeOf(object) === REACT_FRAGMENT_TYPE;
  941. }
  942. function isLazy(object) {
  943. return typeOf(object) === REACT_LAZY_TYPE;
  944. }
  945. function isMemo(object) {
  946. return typeOf(object) === REACT_MEMO_TYPE;
  947. }
  948. function isPortal(object) {
  949. return typeOf(object) === REACT_PORTAL_TYPE;
  950. }
  951. function isProfiler(object) {
  952. return typeOf(object) === REACT_PROFILER_TYPE;
  953. }
  954. function isStrictMode(object) {
  955. return typeOf(object) === REACT_STRICT_MODE_TYPE;
  956. }
  957. function isSuspense(object) {
  958. return typeOf(object) === REACT_SUSPENSE_TYPE;
  959. }
  960. function isSuspenseList(object) {
  961. return typeOf(object) === REACT_SUSPENSE_LIST_TYPE;
  962. }
  963. exports.ContextConsumer = ContextConsumer;
  964. exports.ContextProvider = ContextProvider;
  965. exports.Element = Element;
  966. exports.ForwardRef = ForwardRef;
  967. exports.Fragment = Fragment;
  968. exports.Lazy = Lazy;
  969. exports.Memo = Memo;
  970. exports.Portal = Portal;
  971. exports.Profiler = Profiler;
  972. exports.StrictMode = StrictMode;
  973. exports.Suspense = Suspense;
  974. exports.SuspenseList = SuspenseList;
  975. exports.isAsyncMode = isAsyncMode;
  976. exports.isConcurrentMode = isConcurrentMode;
  977. exports.isContextConsumer = isContextConsumer;
  978. exports.isContextProvider = isContextProvider;
  979. exports.isElement = isElement;
  980. exports.isForwardRef = isForwardRef;
  981. exports.isFragment = isFragment;
  982. exports.isLazy = isLazy;
  983. exports.isMemo = isMemo;
  984. exports.isPortal = isPortal;
  985. exports.isProfiler = isProfiler;
  986. exports.isStrictMode = isStrictMode;
  987. exports.isSuspense = isSuspense;
  988. exports.isSuspenseList = isSuspenseList;
  989. exports.isValidElementType = isValidElementType;
  990. exports.typeOf = typeOf;
  991. })();
  992. }
  993. });
  994. var reactIs = createCommonjsModule(function (module) {
  995. {
  996. module.exports = reactIs_development;
  997. }
  998. });
  999. /**
  1000. * Prints a warning in the console if it exists.
  1001. *
  1002. * @param {String} message The warning message.
  1003. * @returns {void}
  1004. */
  1005. function warning(message) {
  1006. /* eslint-disable no-console */
  1007. if (typeof console !== 'undefined' && typeof console.error === 'function') {
  1008. console.error(message);
  1009. }
  1010. /* eslint-enable no-console */
  1011. try {
  1012. // This error was thrown as a convenience so that if you enable
  1013. // "break on all exceptions" in your console,
  1014. // it would pause the execution at this line.
  1015. throw new Error(message);
  1016. /* eslint-disable no-empty */
  1017. } catch (e) {}
  1018. /* eslint-enable no-empty */
  1019. }
  1020. function verify(selector, methodName) {
  1021. if (!selector) {
  1022. throw new Error(`Unexpected value for ${methodName} in connect.`);
  1023. } else if (methodName === 'mapStateToProps' || methodName === 'mapDispatchToProps') {
  1024. if (!Object.prototype.hasOwnProperty.call(selector, 'dependsOnOwnProps')) {
  1025. warning(`The selector for ${methodName} of connect did not specify a value for dependsOnOwnProps.`);
  1026. }
  1027. }
  1028. }
  1029. function verifySubselectors(mapStateToProps, mapDispatchToProps, mergeProps) {
  1030. verify(mapStateToProps, 'mapStateToProps');
  1031. verify(mapDispatchToProps, 'mapDispatchToProps');
  1032. verify(mergeProps, 'mergeProps');
  1033. }
  1034. const _excluded$1 = ["initMapStateToProps", "initMapDispatchToProps", "initMergeProps"];
  1035. function pureFinalPropsSelectorFactory(mapStateToProps, mapDispatchToProps, mergeProps, dispatch, {
  1036. areStatesEqual,
  1037. areOwnPropsEqual,
  1038. areStatePropsEqual
  1039. }) {
  1040. let hasRunAtLeastOnce = false;
  1041. let state;
  1042. let ownProps;
  1043. let stateProps;
  1044. let dispatchProps;
  1045. let mergedProps;
  1046. function handleFirstCall(firstState, firstOwnProps) {
  1047. state = firstState;
  1048. ownProps = firstOwnProps;
  1049. stateProps = mapStateToProps(state, ownProps);
  1050. dispatchProps = mapDispatchToProps(dispatch, ownProps);
  1051. mergedProps = mergeProps(stateProps, dispatchProps, ownProps);
  1052. hasRunAtLeastOnce = true;
  1053. return mergedProps;
  1054. }
  1055. function handleNewPropsAndNewState() {
  1056. stateProps = mapStateToProps(state, ownProps);
  1057. if (mapDispatchToProps.dependsOnOwnProps) dispatchProps = mapDispatchToProps(dispatch, ownProps);
  1058. mergedProps = mergeProps(stateProps, dispatchProps, ownProps);
  1059. return mergedProps;
  1060. }
  1061. function handleNewProps() {
  1062. if (mapStateToProps.dependsOnOwnProps) stateProps = mapStateToProps(state, ownProps);
  1063. if (mapDispatchToProps.dependsOnOwnProps) dispatchProps = mapDispatchToProps(dispatch, ownProps);
  1064. mergedProps = mergeProps(stateProps, dispatchProps, ownProps);
  1065. return mergedProps;
  1066. }
  1067. function handleNewState() {
  1068. const nextStateProps = mapStateToProps(state, ownProps);
  1069. const statePropsChanged = !areStatePropsEqual(nextStateProps, stateProps);
  1070. stateProps = nextStateProps;
  1071. if (statePropsChanged) mergedProps = mergeProps(stateProps, dispatchProps, ownProps);
  1072. return mergedProps;
  1073. }
  1074. function handleSubsequentCalls(nextState, nextOwnProps) {
  1075. const propsChanged = !areOwnPropsEqual(nextOwnProps, ownProps);
  1076. const stateChanged = !areStatesEqual(nextState, state, nextOwnProps, ownProps);
  1077. state = nextState;
  1078. ownProps = nextOwnProps;
  1079. if (propsChanged && stateChanged) return handleNewPropsAndNewState();
  1080. if (propsChanged) return handleNewProps();
  1081. if (stateChanged) return handleNewState();
  1082. return mergedProps;
  1083. }
  1084. return function pureFinalPropsSelector(nextState, nextOwnProps) {
  1085. return hasRunAtLeastOnce ? handleSubsequentCalls(nextState, nextOwnProps) : handleFirstCall(nextState, nextOwnProps);
  1086. };
  1087. }
  1088. // TODO: Add more comments
  1089. // The selector returned by selectorFactory will memoize its results,
  1090. // allowing connect's shouldComponentUpdate to return false if final
  1091. // props have not changed.
  1092. function finalPropsSelectorFactory(dispatch, _ref) {
  1093. let {
  1094. initMapStateToProps,
  1095. initMapDispatchToProps,
  1096. initMergeProps
  1097. } = _ref,
  1098. options = _objectWithoutPropertiesLoose(_ref, _excluded$1);
  1099. const mapStateToProps = initMapStateToProps(dispatch, options);
  1100. const mapDispatchToProps = initMapDispatchToProps(dispatch, options);
  1101. const mergeProps = initMergeProps(dispatch, options);
  1102. {
  1103. verifySubselectors(mapStateToProps, mapDispatchToProps, mergeProps);
  1104. }
  1105. return pureFinalPropsSelectorFactory(mapStateToProps, mapDispatchToProps, mergeProps, dispatch, options);
  1106. }
  1107. function bindActionCreators(actionCreators, dispatch) {
  1108. const boundActionCreators = {};
  1109. for (const key in actionCreators) {
  1110. const actionCreator = actionCreators[key];
  1111. if (typeof actionCreator === 'function') {
  1112. boundActionCreators[key] = (...args) => dispatch(actionCreator(...args));
  1113. }
  1114. }
  1115. return boundActionCreators;
  1116. }
  1117. /**
  1118. * @param {any} obj The object to inspect.
  1119. * @returns {boolean} True if the argument appears to be a plain object.
  1120. */
  1121. function isPlainObject(obj) {
  1122. if (typeof obj !== 'object' || obj === null) return false;
  1123. let proto = Object.getPrototypeOf(obj);
  1124. if (proto === null) return true;
  1125. let baseProto = proto;
  1126. while (Object.getPrototypeOf(baseProto) !== null) {
  1127. baseProto = Object.getPrototypeOf(baseProto);
  1128. }
  1129. return proto === baseProto;
  1130. }
  1131. function verifyPlainObject(value, displayName, methodName) {
  1132. if (!isPlainObject(value)) {
  1133. warning(`${methodName}() in ${displayName} must return a plain object. Instead received ${value}.`);
  1134. }
  1135. }
  1136. function wrapMapToPropsConstant( // * Note:
  1137. // It seems that the dispatch argument
  1138. // could be a dispatch function in some cases (ex: whenMapDispatchToPropsIsMissing)
  1139. // and a state object in some others (ex: whenMapStateToPropsIsMissing)
  1140. // eslint-disable-next-line no-unused-vars
  1141. getConstant) {
  1142. return function initConstantSelector(dispatch) {
  1143. const constant = getConstant(dispatch);
  1144. function constantSelector() {
  1145. return constant;
  1146. }
  1147. constantSelector.dependsOnOwnProps = false;
  1148. return constantSelector;
  1149. };
  1150. } // dependsOnOwnProps is used by createMapToPropsProxy to determine whether to pass props as args
  1151. // to the mapToProps function being wrapped. It is also used by makePurePropsSelector to determine
  1152. // whether mapToProps needs to be invoked when props have changed.
  1153. //
  1154. // A length of one signals that mapToProps does not depend on props from the parent component.
  1155. // A length of zero is assumed to mean mapToProps is getting args via arguments or ...args and
  1156. // therefore not reporting its length accurately..
  1157. // TODO Can this get pulled out so that we can subscribe directly to the store if we don't need ownProps?
  1158. function getDependsOnOwnProps(mapToProps) {
  1159. return mapToProps.dependsOnOwnProps ? Boolean(mapToProps.dependsOnOwnProps) : mapToProps.length !== 1;
  1160. } // Used by whenMapStateToPropsIsFunction and whenMapDispatchToPropsIsFunction,
  1161. // this function wraps mapToProps in a proxy function which does several things:
  1162. //
  1163. // * Detects whether the mapToProps function being called depends on props, which
  1164. // is used by selectorFactory to decide if it should reinvoke on props changes.
  1165. //
  1166. // * On first call, handles mapToProps if returns another function, and treats that
  1167. // new function as the true mapToProps for subsequent calls.
  1168. //
  1169. // * On first call, verifies the first result is a plain object, in order to warn
  1170. // the developer that their mapToProps function is not returning a valid result.
  1171. //
  1172. function wrapMapToPropsFunc(mapToProps, methodName) {
  1173. return function initProxySelector(dispatch, {
  1174. displayName
  1175. }) {
  1176. const proxy = function mapToPropsProxy(stateOrDispatch, ownProps) {
  1177. return proxy.dependsOnOwnProps ? proxy.mapToProps(stateOrDispatch, ownProps) : proxy.mapToProps(stateOrDispatch, undefined);
  1178. }; // allow detectFactoryAndVerify to get ownProps
  1179. proxy.dependsOnOwnProps = true;
  1180. proxy.mapToProps = function detectFactoryAndVerify(stateOrDispatch, ownProps) {
  1181. proxy.mapToProps = mapToProps;
  1182. proxy.dependsOnOwnProps = getDependsOnOwnProps(mapToProps);
  1183. let props = proxy(stateOrDispatch, ownProps);
  1184. if (typeof props === 'function') {
  1185. proxy.mapToProps = props;
  1186. proxy.dependsOnOwnProps = getDependsOnOwnProps(props);
  1187. props = proxy(stateOrDispatch, ownProps);
  1188. }
  1189. verifyPlainObject(props, displayName, methodName);
  1190. return props;
  1191. };
  1192. return proxy;
  1193. };
  1194. }
  1195. function createInvalidArgFactory(arg, name) {
  1196. return (dispatch, options) => {
  1197. throw new Error(`Invalid value of type ${typeof arg} for ${name} argument when connecting component ${options.wrappedComponentName}.`);
  1198. };
  1199. }
  1200. function mapDispatchToPropsFactory(mapDispatchToProps) {
  1201. return mapDispatchToProps && typeof mapDispatchToProps === 'object' ? wrapMapToPropsConstant(dispatch => // @ts-ignore
  1202. bindActionCreators(mapDispatchToProps, dispatch)) : !mapDispatchToProps ? wrapMapToPropsConstant(dispatch => ({
  1203. dispatch
  1204. })) : typeof mapDispatchToProps === 'function' ? // @ts-ignore
  1205. wrapMapToPropsFunc(mapDispatchToProps, 'mapDispatchToProps') : createInvalidArgFactory(mapDispatchToProps, 'mapDispatchToProps');
  1206. }
  1207. function mapStateToPropsFactory(mapStateToProps) {
  1208. return !mapStateToProps ? wrapMapToPropsConstant(() => ({})) : typeof mapStateToProps === 'function' ? // @ts-ignore
  1209. wrapMapToPropsFunc(mapStateToProps, 'mapStateToProps') : createInvalidArgFactory(mapStateToProps, 'mapStateToProps');
  1210. }
  1211. function defaultMergeProps(stateProps, dispatchProps, ownProps) {
  1212. // @ts-ignore
  1213. return _extends({}, ownProps, stateProps, dispatchProps);
  1214. }
  1215. function wrapMergePropsFunc(mergeProps) {
  1216. return function initMergePropsProxy(dispatch, {
  1217. displayName,
  1218. areMergedPropsEqual
  1219. }) {
  1220. let hasRunOnce = false;
  1221. let mergedProps;
  1222. return function mergePropsProxy(stateProps, dispatchProps, ownProps) {
  1223. const nextMergedProps = mergeProps(stateProps, dispatchProps, ownProps);
  1224. if (hasRunOnce) {
  1225. if (!areMergedPropsEqual(nextMergedProps, mergedProps)) mergedProps = nextMergedProps;
  1226. } else {
  1227. hasRunOnce = true;
  1228. mergedProps = nextMergedProps;
  1229. verifyPlainObject(mergedProps, displayName, 'mergeProps');
  1230. }
  1231. return mergedProps;
  1232. };
  1233. };
  1234. }
  1235. function mergePropsFactory(mergeProps) {
  1236. return !mergeProps ? () => defaultMergeProps : typeof mergeProps === 'function' ? wrapMergePropsFunc(mergeProps) : createInvalidArgFactory(mergeProps, 'mergeProps');
  1237. }
  1238. // well as nesting subscriptions of descendant components, so that we can ensure the
  1239. // ancestor components re-render before descendants
  1240. function createListenerCollection() {
  1241. const batch = getBatch();
  1242. let first = null;
  1243. let last = null;
  1244. return {
  1245. clear() {
  1246. first = null;
  1247. last = null;
  1248. },
  1249. notify() {
  1250. batch(() => {
  1251. let listener = first;
  1252. while (listener) {
  1253. listener.callback();
  1254. listener = listener.next;
  1255. }
  1256. });
  1257. },
  1258. get() {
  1259. let listeners = [];
  1260. let listener = first;
  1261. while (listener) {
  1262. listeners.push(listener);
  1263. listener = listener.next;
  1264. }
  1265. return listeners;
  1266. },
  1267. subscribe(callback) {
  1268. let isSubscribed = true;
  1269. let listener = last = {
  1270. callback,
  1271. next: null,
  1272. prev: last
  1273. };
  1274. if (listener.prev) {
  1275. listener.prev.next = listener;
  1276. } else {
  1277. first = listener;
  1278. }
  1279. return function unsubscribe() {
  1280. if (!isSubscribed || first === null) return;
  1281. isSubscribed = false;
  1282. if (listener.next) {
  1283. listener.next.prev = listener.prev;
  1284. } else {
  1285. last = listener.prev;
  1286. }
  1287. if (listener.prev) {
  1288. listener.prev.next = listener.next;
  1289. } else {
  1290. first = listener.next;
  1291. }
  1292. };
  1293. }
  1294. };
  1295. }
  1296. const nullListeners = {
  1297. notify() {},
  1298. get: () => []
  1299. };
  1300. function createSubscription(store, parentSub) {
  1301. let unsubscribe;
  1302. let listeners = nullListeners; // Reasons to keep the subscription active
  1303. let subscriptionsAmount = 0; // Is this specific subscription subscribed (or only nested ones?)
  1304. let selfSubscribed = false;
  1305. function addNestedSub(listener) {
  1306. trySubscribe();
  1307. const cleanupListener = listeners.subscribe(listener); // cleanup nested sub
  1308. let removed = false;
  1309. return () => {
  1310. if (!removed) {
  1311. removed = true;
  1312. cleanupListener();
  1313. tryUnsubscribe();
  1314. }
  1315. };
  1316. }
  1317. function notifyNestedSubs() {
  1318. listeners.notify();
  1319. }
  1320. function handleChangeWrapper() {
  1321. if (subscription.onStateChange) {
  1322. subscription.onStateChange();
  1323. }
  1324. }
  1325. function isSubscribed() {
  1326. return selfSubscribed;
  1327. }
  1328. function trySubscribe() {
  1329. subscriptionsAmount++;
  1330. if (!unsubscribe) {
  1331. unsubscribe = parentSub ? parentSub.addNestedSub(handleChangeWrapper) : store.subscribe(handleChangeWrapper);
  1332. listeners = createListenerCollection();
  1333. }
  1334. }
  1335. function tryUnsubscribe() {
  1336. subscriptionsAmount--;
  1337. if (unsubscribe && subscriptionsAmount === 0) {
  1338. unsubscribe();
  1339. unsubscribe = undefined;
  1340. listeners.clear();
  1341. listeners = nullListeners;
  1342. }
  1343. }
  1344. function trySubscribeSelf() {
  1345. if (!selfSubscribed) {
  1346. selfSubscribed = true;
  1347. trySubscribe();
  1348. }
  1349. }
  1350. function tryUnsubscribeSelf() {
  1351. if (selfSubscribed) {
  1352. selfSubscribed = false;
  1353. tryUnsubscribe();
  1354. }
  1355. }
  1356. const subscription = {
  1357. addNestedSub,
  1358. notifyNestedSubs,
  1359. handleChangeWrapper,
  1360. isSubscribed,
  1361. trySubscribe: trySubscribeSelf,
  1362. tryUnsubscribe: tryUnsubscribeSelf,
  1363. getListeners: () => listeners
  1364. };
  1365. return subscription;
  1366. }
  1367. // To get around it, we can conditionally useEffect on the server (no-op) and
  1368. // useLayoutEffect in the browser. We need useLayoutEffect to ensure the store
  1369. // subscription callback always has the selector from the latest render commit
  1370. // available, otherwise a store update may happen between render and the effect,
  1371. // which may cause missed updates; we also must ensure the store subscription
  1372. // is created synchronously, otherwise a store update may occur before the
  1373. // subscription is created and an inconsistent state may be observed
  1374. // Matches logic in React's `shared/ExecutionEnvironment` file
  1375. const canUseDOM = !!(typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined');
  1376. const useIsomorphicLayoutEffect = canUseDOM ? React__namespace.useLayoutEffect : React__namespace.useEffect;
  1377. function is(x, y) {
  1378. if (x === y) {
  1379. return x !== 0 || y !== 0 || 1 / x === 1 / y;
  1380. } else {
  1381. return x !== x && y !== y;
  1382. }
  1383. }
  1384. function shallowEqual(objA, objB) {
  1385. if (is(objA, objB)) return true;
  1386. if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {
  1387. return false;
  1388. }
  1389. const keysA = Object.keys(objA);
  1390. const keysB = Object.keys(objB);
  1391. if (keysA.length !== keysB.length) return false;
  1392. for (let i = 0; i < keysA.length; i++) {
  1393. if (!Object.prototype.hasOwnProperty.call(objB, keysA[i]) || !is(objA[keysA[i]], objB[keysA[i]])) {
  1394. return false;
  1395. }
  1396. }
  1397. return true;
  1398. }
  1399. const _excluded = ["reactReduxForwardedRef"];
  1400. let useSyncExternalStore = notInitialized;
  1401. const initializeConnect = fn => {
  1402. useSyncExternalStore = fn;
  1403. }; // Define some constant arrays just to avoid re-creating these
  1404. const NO_SUBSCRIPTION_ARRAY = [null, null]; // Attempts to stringify whatever not-really-a-component value we were given
  1405. // for logging in an error message
  1406. const stringifyComponent = Comp => {
  1407. try {
  1408. return JSON.stringify(Comp);
  1409. } catch (err) {
  1410. return String(Comp);
  1411. }
  1412. };
  1413. // This is "just" a `useLayoutEffect`, but with two modifications:
  1414. // - we need to fall back to `useEffect` in SSR to avoid annoying warnings
  1415. // - we extract this to a separate function to avoid closing over values
  1416. // and causing memory leaks
  1417. function useIsomorphicLayoutEffectWithArgs(effectFunc, effectArgs, dependencies) {
  1418. useIsomorphicLayoutEffect(() => effectFunc(...effectArgs), dependencies);
  1419. } // Effect callback, extracted: assign the latest props values to refs for later usage
  1420. function captureWrapperProps(lastWrapperProps, lastChildProps, renderIsScheduled, wrapperProps, // actualChildProps: unknown,
  1421. childPropsFromStoreUpdate, notifyNestedSubs) {
  1422. // We want to capture the wrapper props and child props we used for later comparisons
  1423. lastWrapperProps.current = wrapperProps;
  1424. renderIsScheduled.current = false; // If the render was from a store update, clear out that reference and cascade the subscriber update
  1425. if (childPropsFromStoreUpdate.current) {
  1426. childPropsFromStoreUpdate.current = null;
  1427. notifyNestedSubs();
  1428. }
  1429. } // Effect callback, extracted: subscribe to the Redux store or nearest connected ancestor,
  1430. // check for updates after dispatched actions, and trigger re-renders.
  1431. function subscribeUpdates(shouldHandleStateChanges, store, subscription, childPropsSelector, lastWrapperProps, lastChildProps, renderIsScheduled, isMounted, childPropsFromStoreUpdate, notifyNestedSubs, // forceComponentUpdateDispatch: React.Dispatch<any>,
  1432. additionalSubscribeListener) {
  1433. // If we're not subscribed to the store, nothing to do here
  1434. if (!shouldHandleStateChanges) return () => {}; // Capture values for checking if and when this component unmounts
  1435. let didUnsubscribe = false;
  1436. let lastThrownError = null; // We'll run this callback every time a store subscription update propagates to this component
  1437. const checkForUpdates = () => {
  1438. if (didUnsubscribe || !isMounted.current) {
  1439. // Don't run stale listeners.
  1440. // Redux doesn't guarantee unsubscriptions happen until next dispatch.
  1441. return;
  1442. } // TODO We're currently calling getState ourselves here, rather than letting `uSES` do it
  1443. const latestStoreState = store.getState();
  1444. let newChildProps, error;
  1445. try {
  1446. // Actually run the selector with the most recent store state and wrapper props
  1447. // to determine what the child props should be
  1448. newChildProps = childPropsSelector(latestStoreState, lastWrapperProps.current);
  1449. } catch (e) {
  1450. error = e;
  1451. lastThrownError = e;
  1452. }
  1453. if (!error) {
  1454. lastThrownError = null;
  1455. } // If the child props haven't changed, nothing to do here - cascade the subscription update
  1456. if (newChildProps === lastChildProps.current) {
  1457. if (!renderIsScheduled.current) {
  1458. notifyNestedSubs();
  1459. }
  1460. } else {
  1461. // Save references to the new child props. Note that we track the "child props from store update"
  1462. // as a ref instead of a useState/useReducer because we need a way to determine if that value has
  1463. // been processed. If this went into useState/useReducer, we couldn't clear out the value without
  1464. // forcing another re-render, which we don't want.
  1465. lastChildProps.current = newChildProps;
  1466. childPropsFromStoreUpdate.current = newChildProps;
  1467. renderIsScheduled.current = true; // TODO This is hacky and not how `uSES` is meant to be used
  1468. // Trigger the React `useSyncExternalStore` subscriber
  1469. additionalSubscribeListener();
  1470. }
  1471. }; // Actually subscribe to the nearest connected ancestor (or store)
  1472. subscription.onStateChange = checkForUpdates;
  1473. subscription.trySubscribe(); // Pull data from the store after first render in case the store has
  1474. // changed since we began.
  1475. checkForUpdates();
  1476. const unsubscribeWrapper = () => {
  1477. didUnsubscribe = true;
  1478. subscription.tryUnsubscribe();
  1479. subscription.onStateChange = null;
  1480. if (lastThrownError) {
  1481. // It's possible that we caught an error due to a bad mapState function, but the
  1482. // parent re-rendered without this component and we're about to unmount.
  1483. // This shouldn't happen as long as we do top-down subscriptions correctly, but
  1484. // if we ever do those wrong, this throw will surface the error in our tests.
  1485. // In that case, throw the error from here so it doesn't get lost.
  1486. throw lastThrownError;
  1487. }
  1488. };
  1489. return unsubscribeWrapper;
  1490. } // Reducer initial state creation for our update reducer
  1491. function strictEqual(a, b) {
  1492. return a === b;
  1493. }
  1494. /**
  1495. * Infers the type of props that a connector will inject into a component.
  1496. */
  1497. let hasWarnedAboutDeprecatedPureOption = false;
  1498. /**
  1499. * Connects a React component to a Redux store.
  1500. *
  1501. * - Without arguments, just wraps the component, without changing the behavior / props
  1502. *
  1503. * - If 2 params are passed (3rd param, mergeProps, is skipped), default behavior
  1504. * is to override ownProps (as stated in the docs), so what remains is everything that's
  1505. * not a state or dispatch prop
  1506. *
  1507. * - When 3rd param is passed, we don't know if ownProps propagate and whether they
  1508. * should be valid component props, because it depends on mergeProps implementation.
  1509. * As such, it is the user's responsibility to extend ownProps interface from state or
  1510. * dispatch props or both when applicable
  1511. *
  1512. * @param mapStateToProps A function that extracts values from state
  1513. * @param mapDispatchToProps Setup for dispatching actions
  1514. * @param mergeProps Optional callback to merge state and dispatch props together
  1515. * @param options Options for configuring the connection
  1516. *
  1517. */
  1518. function connect(mapStateToProps, mapDispatchToProps, mergeProps, {
  1519. // The `pure` option has been removed, so TS doesn't like us destructuring this to check its existence.
  1520. // @ts-ignore
  1521. pure,
  1522. areStatesEqual = strictEqual,
  1523. areOwnPropsEqual = shallowEqual,
  1524. areStatePropsEqual = shallowEqual,
  1525. areMergedPropsEqual = shallowEqual,
  1526. // use React's forwardRef to expose a ref of the wrapped component
  1527. forwardRef = false,
  1528. // the context consumer to use
  1529. context = ReactReduxContext
  1530. } = {}) {
  1531. {
  1532. if (pure !== undefined && !hasWarnedAboutDeprecatedPureOption) {
  1533. hasWarnedAboutDeprecatedPureOption = true;
  1534. warning('The `pure` option has been removed. `connect` is now always a "pure/memoized" component');
  1535. }
  1536. }
  1537. const Context = context;
  1538. const initMapStateToProps = mapStateToPropsFactory(mapStateToProps);
  1539. const initMapDispatchToProps = mapDispatchToPropsFactory(mapDispatchToProps);
  1540. const initMergeProps = mergePropsFactory(mergeProps);
  1541. const shouldHandleStateChanges = Boolean(mapStateToProps);
  1542. const wrapWithConnect = WrappedComponent => {
  1543. if (!reactIs.isValidElementType(WrappedComponent)) {
  1544. throw new Error(`You must pass a component to the function returned by connect. Instead received ${stringifyComponent(WrappedComponent)}`);
  1545. }
  1546. const wrappedComponentName = WrappedComponent.displayName || WrappedComponent.name || 'Component';
  1547. const displayName = `Connect(${wrappedComponentName})`;
  1548. const selectorFactoryOptions = {
  1549. shouldHandleStateChanges,
  1550. displayName,
  1551. wrappedComponentName,
  1552. WrappedComponent,
  1553. // @ts-ignore
  1554. initMapStateToProps,
  1555. // @ts-ignore
  1556. initMapDispatchToProps,
  1557. initMergeProps,
  1558. areStatesEqual,
  1559. areStatePropsEqual,
  1560. areOwnPropsEqual,
  1561. areMergedPropsEqual
  1562. };
  1563. function ConnectFunction(props) {
  1564. const [propsContext, reactReduxForwardedRef, wrapperProps] = React__namespace.useMemo(() => {
  1565. // Distinguish between actual "data" props that were passed to the wrapper component,
  1566. // and values needed to control behavior (forwarded refs, alternate context instances).
  1567. // To maintain the wrapperProps object reference, memoize this destructuring.
  1568. const {
  1569. reactReduxForwardedRef
  1570. } = props,
  1571. wrapperProps = _objectWithoutPropertiesLoose(props, _excluded);
  1572. return [props.context, reactReduxForwardedRef, wrapperProps];
  1573. }, [props]);
  1574. const ContextToUse = React__namespace.useMemo(() => {
  1575. // Users may optionally pass in a custom context instance to use instead of our ReactReduxContext.
  1576. // Memoize the check that determines which context instance we should use.
  1577. return propsContext && propsContext.Consumer && // @ts-ignore
  1578. reactIs.isContextConsumer( /*#__PURE__*/React__namespace.createElement(propsContext.Consumer, null)) ? propsContext : Context;
  1579. }, [propsContext, Context]); // Retrieve the store and ancestor subscription via context, if available
  1580. const contextValue = React__namespace.useContext(ContextToUse); // The store _must_ exist as either a prop or in context.
  1581. // We'll check to see if it _looks_ like a Redux store first.
  1582. // This allows us to pass through a `store` prop that is just a plain value.
  1583. const didStoreComeFromProps = Boolean(props.store) && Boolean(props.store.getState) && Boolean(props.store.dispatch);
  1584. const didStoreComeFromContext = Boolean(contextValue) && Boolean(contextValue.store);
  1585. if (!didStoreComeFromProps && !didStoreComeFromContext) {
  1586. throw new Error(`Could not find "store" in the context of ` + `"${displayName}". Either wrap the root component in a <Provider>, ` + `or pass a custom React context provider to <Provider> and the corresponding ` + `React context consumer to ${displayName} in connect options.`);
  1587. } // Based on the previous check, one of these must be true
  1588. const store = didStoreComeFromProps ? props.store : contextValue.store;
  1589. const getServerState = didStoreComeFromContext ? contextValue.getServerState : store.getState;
  1590. const childPropsSelector = React__namespace.useMemo(() => {
  1591. // The child props selector needs the store reference as an input.
  1592. // Re-create this selector whenever the store changes.
  1593. return finalPropsSelectorFactory(store.dispatch, selectorFactoryOptions);
  1594. }, [store]);
  1595. const [subscription, notifyNestedSubs] = React__namespace.useMemo(() => {
  1596. if (!shouldHandleStateChanges) return NO_SUBSCRIPTION_ARRAY; // This Subscription's source should match where store came from: props vs. context. A component
  1597. // connected to the store via props shouldn't use subscription from context, or vice versa.
  1598. const subscription = createSubscription(store, didStoreComeFromProps ? undefined : contextValue.subscription); // `notifyNestedSubs` is duplicated to handle the case where the component is unmounted in
  1599. // the middle of the notification loop, where `subscription` will then be null. This can
  1600. // probably be avoided if Subscription's listeners logic is changed to not call listeners
  1601. // that have been unsubscribed in the middle of the notification loop.
  1602. const notifyNestedSubs = subscription.notifyNestedSubs.bind(subscription);
  1603. return [subscription, notifyNestedSubs];
  1604. }, [store, didStoreComeFromProps, contextValue]); // Determine what {store, subscription} value should be put into nested context, if necessary,
  1605. // and memoize that value to avoid unnecessary context updates.
  1606. const overriddenContextValue = React__namespace.useMemo(() => {
  1607. if (didStoreComeFromProps) {
  1608. // This component is directly subscribed to a store from props.
  1609. // We don't want descendants reading from this store - pass down whatever
  1610. // the existing context value is from the nearest connected ancestor.
  1611. return contextValue;
  1612. } // Otherwise, put this component's subscription instance into context, so that
  1613. // connected descendants won't update until after this component is done
  1614. return _extends({}, contextValue, {
  1615. subscription
  1616. });
  1617. }, [didStoreComeFromProps, contextValue, subscription]); // Set up refs to coordinate values between the subscription effect and the render logic
  1618. const lastChildProps = React__namespace.useRef();
  1619. const lastWrapperProps = React__namespace.useRef(wrapperProps);
  1620. const childPropsFromStoreUpdate = React__namespace.useRef();
  1621. const renderIsScheduled = React__namespace.useRef(false);
  1622. React__namespace.useRef(false);
  1623. const isMounted = React__namespace.useRef(false);
  1624. const latestSubscriptionCallbackError = React__namespace.useRef();
  1625. useIsomorphicLayoutEffect(() => {
  1626. isMounted.current = true;
  1627. return () => {
  1628. isMounted.current = false;
  1629. };
  1630. }, []);
  1631. const actualChildPropsSelector = React__namespace.useMemo(() => {
  1632. const selector = () => {
  1633. // Tricky logic here:
  1634. // - This render may have been triggered by a Redux store update that produced new child props
  1635. // - However, we may have gotten new wrapper props after that
  1636. // If we have new child props, and the same wrapper props, we know we should use the new child props as-is.
  1637. // But, if we have new wrapper props, those might change the child props, so we have to recalculate things.
  1638. // So, we'll use the child props from store update only if the wrapper props are the same as last time.
  1639. if (childPropsFromStoreUpdate.current && wrapperProps === lastWrapperProps.current) {
  1640. return childPropsFromStoreUpdate.current;
  1641. } // TODO We're reading the store directly in render() here. Bad idea?
  1642. // This will likely cause Bad Things (TM) to happen in Concurrent Mode.
  1643. // Note that we do this because on renders _not_ caused by store updates, we need the latest store state
  1644. // to determine what the child props should be.
  1645. return childPropsSelector(store.getState(), wrapperProps);
  1646. };
  1647. return selector;
  1648. }, [store, wrapperProps]); // We need this to execute synchronously every time we re-render. However, React warns
  1649. // about useLayoutEffect in SSR, so we try to detect environment and fall back to
  1650. // just useEffect instead to avoid the warning, since neither will run anyway.
  1651. const subscribeForReact = React__namespace.useMemo(() => {
  1652. const subscribe = reactListener => {
  1653. if (!subscription) {
  1654. return () => {};
  1655. }
  1656. return subscribeUpdates(shouldHandleStateChanges, store, subscription, // @ts-ignore
  1657. childPropsSelector, lastWrapperProps, lastChildProps, renderIsScheduled, isMounted, childPropsFromStoreUpdate, notifyNestedSubs, reactListener);
  1658. };
  1659. return subscribe;
  1660. }, [subscription]);
  1661. useIsomorphicLayoutEffectWithArgs(captureWrapperProps, [lastWrapperProps, lastChildProps, renderIsScheduled, wrapperProps, childPropsFromStoreUpdate, notifyNestedSubs]);
  1662. let actualChildProps;
  1663. try {
  1664. actualChildProps = useSyncExternalStore( // TODO We're passing through a big wrapper that does a bunch of extra side effects besides subscribing
  1665. subscribeForReact, // TODO This is incredibly hacky. We've already processed the store update and calculated new child props,
  1666. // TODO and we're just passing that through so it triggers a re-render for us rather than relying on `uSES`.
  1667. actualChildPropsSelector, getServerState ? () => childPropsSelector(getServerState(), wrapperProps) : actualChildPropsSelector);
  1668. } catch (err) {
  1669. if (latestSubscriptionCallbackError.current) {
  1670. err.message += `\nThe error may be correlated with this previous error:\n${latestSubscriptionCallbackError.current.stack}\n\n`;
  1671. }
  1672. throw err;
  1673. }
  1674. useIsomorphicLayoutEffect(() => {
  1675. latestSubscriptionCallbackError.current = undefined;
  1676. childPropsFromStoreUpdate.current = undefined;
  1677. lastChildProps.current = actualChildProps;
  1678. }); // Now that all that's done, we can finally try to actually render the child component.
  1679. // We memoize the elements for the rendered child component as an optimization.
  1680. const renderedWrappedComponent = React__namespace.useMemo(() => {
  1681. return (
  1682. /*#__PURE__*/
  1683. // @ts-ignore
  1684. React__namespace.createElement(WrappedComponent, _extends({}, actualChildProps, {
  1685. ref: reactReduxForwardedRef
  1686. }))
  1687. );
  1688. }, [reactReduxForwardedRef, WrappedComponent, actualChildProps]); // If React sees the exact same element reference as last time, it bails out of re-rendering
  1689. // that child, same as if it was wrapped in React.memo() or returned false from shouldComponentUpdate.
  1690. const renderedChild = React__namespace.useMemo(() => {
  1691. if (shouldHandleStateChanges) {
  1692. // If this component is subscribed to store updates, we need to pass its own
  1693. // subscription instance down to our descendants. That means rendering the same
  1694. // Context instance, and putting a different value into the context.
  1695. return /*#__PURE__*/React__namespace.createElement(ContextToUse.Provider, {
  1696. value: overriddenContextValue
  1697. }, renderedWrappedComponent);
  1698. }
  1699. return renderedWrappedComponent;
  1700. }, [ContextToUse, renderedWrappedComponent, overriddenContextValue]);
  1701. return renderedChild;
  1702. }
  1703. const _Connect = React__namespace.memo(ConnectFunction);
  1704. // Add a hacky cast to get the right output type
  1705. const Connect = _Connect;
  1706. Connect.WrappedComponent = WrappedComponent;
  1707. Connect.displayName = ConnectFunction.displayName = displayName;
  1708. if (forwardRef) {
  1709. const _forwarded = React__namespace.forwardRef(function forwardConnectRef(props, ref) {
  1710. // @ts-ignore
  1711. return /*#__PURE__*/React__namespace.createElement(Connect, _extends({}, props, {
  1712. reactReduxForwardedRef: ref
  1713. }));
  1714. });
  1715. const forwarded = _forwarded;
  1716. forwarded.displayName = displayName;
  1717. forwarded.WrappedComponent = WrappedComponent;
  1718. return hoistNonReactStatics_cjs(forwarded, WrappedComponent);
  1719. }
  1720. return hoistNonReactStatics_cjs(Connect, WrappedComponent);
  1721. };
  1722. return wrapWithConnect;
  1723. }
  1724. function Provider({
  1725. store,
  1726. context,
  1727. children,
  1728. serverState,
  1729. stabilityCheck = 'once',
  1730. noopCheck = 'once'
  1731. }) {
  1732. const contextValue = React__namespace.useMemo(() => {
  1733. const subscription = createSubscription(store);
  1734. return {
  1735. store,
  1736. subscription,
  1737. getServerState: serverState ? () => serverState : undefined,
  1738. stabilityCheck,
  1739. noopCheck
  1740. };
  1741. }, [store, serverState, stabilityCheck, noopCheck]);
  1742. const previousState = React__namespace.useMemo(() => store.getState(), [store]);
  1743. useIsomorphicLayoutEffect(() => {
  1744. const {
  1745. subscription
  1746. } = contextValue;
  1747. subscription.onStateChange = subscription.notifyNestedSubs;
  1748. subscription.trySubscribe();
  1749. if (previousState !== store.getState()) {
  1750. subscription.notifyNestedSubs();
  1751. }
  1752. return () => {
  1753. subscription.tryUnsubscribe();
  1754. subscription.onStateChange = undefined;
  1755. };
  1756. }, [contextValue, previousState]);
  1757. const Context = context || ReactReduxContext; // @ts-ignore 'AnyAction' is assignable to the constraint of type 'A', but 'A' could be instantiated with a different subtype
  1758. return /*#__PURE__*/React__namespace.createElement(Context.Provider, {
  1759. value: contextValue
  1760. }, children);
  1761. }
  1762. /**
  1763. * Hook factory, which creates a `useStore` hook bound to a given context.
  1764. *
  1765. * @param {React.Context} [context=ReactReduxContext] Context passed to your `<Provider>`.
  1766. * @returns {Function} A `useStore` hook bound to the specified context.
  1767. */
  1768. function createStoreHook(context = ReactReduxContext) {
  1769. const useReduxContext$1 = // @ts-ignore
  1770. context === ReactReduxContext ? useReduxContext : // @ts-ignore
  1771. createReduxContextHook(context);
  1772. return function useStore() {
  1773. const {
  1774. store
  1775. } = useReduxContext$1(); // @ts-ignore
  1776. return store;
  1777. };
  1778. }
  1779. /**
  1780. * A hook to access the redux store.
  1781. *
  1782. * @returns {any} the redux store
  1783. *
  1784. * @example
  1785. *
  1786. * import React from 'react'
  1787. * import { useStore } from 'react-redux'
  1788. *
  1789. * export const ExampleComponent = () => {
  1790. * const store = useStore()
  1791. * return <div>{store.getState()}</div>
  1792. * }
  1793. */
  1794. const useStore = /*#__PURE__*/createStoreHook();
  1795. /**
  1796. * Hook factory, which creates a `useDispatch` hook bound to a given context.
  1797. *
  1798. * @param {React.Context} [context=ReactReduxContext] Context passed to your `<Provider>`.
  1799. * @returns {Function} A `useDispatch` hook bound to the specified context.
  1800. */
  1801. function createDispatchHook(context = ReactReduxContext) {
  1802. const useStore$1 = // @ts-ignore
  1803. context === ReactReduxContext ? useStore : createStoreHook(context);
  1804. return function useDispatch() {
  1805. const store = useStore$1(); // @ts-ignore
  1806. return store.dispatch;
  1807. };
  1808. }
  1809. /**
  1810. * A hook to access the redux `dispatch` function.
  1811. *
  1812. * @returns {any|function} redux store's `dispatch` function
  1813. *
  1814. * @example
  1815. *
  1816. * import React, { useCallback } from 'react'
  1817. * import { useDispatch } from 'react-redux'
  1818. *
  1819. * export const CounterComponent = ({ value }) => {
  1820. * const dispatch = useDispatch()
  1821. * const increaseCounter = useCallback(() => dispatch({ type: 'increase-counter' }), [])
  1822. * return (
  1823. * <div>
  1824. * <span>{value}</span>
  1825. * <button onClick={increaseCounter}>Increase counter</button>
  1826. * </div>
  1827. * )
  1828. * }
  1829. */
  1830. const useDispatch = /*#__PURE__*/createDispatchHook();
  1831. // The primary entry point assumes we're working with standard ReactDOM/RN, but
  1832. initializeUseSelector(withSelector.useSyncExternalStoreWithSelector);
  1833. initializeConnect(shim.useSyncExternalStore); // Enable batched updates in our subscriptions for use
  1834. // with standard React renderers (ReactDOM, React Native)
  1835. setBatch(reactDom.unstable_batchedUpdates);
  1836. Object.defineProperty(exports, 'batch', {
  1837. enumerable: true,
  1838. get: function () {
  1839. return reactDom.unstable_batchedUpdates;
  1840. }
  1841. });
  1842. exports.Provider = Provider;
  1843. exports.ReactReduxContext = ReactReduxContext;
  1844. exports.connect = connect;
  1845. exports.createDispatchHook = createDispatchHook;
  1846. exports.createSelectorHook = createSelectorHook;
  1847. exports.createStoreHook = createStoreHook;
  1848. exports.shallowEqual = shallowEqual;
  1849. exports.useDispatch = useDispatch;
  1850. exports.useSelector = useSelector;
  1851. exports.useStore = useStore;
  1852. Object.defineProperty(exports, '__esModule', { value: true });
  1853. })));