source: node_modules/react-redux/dist/cjs/react-redux.development.cjs@ a762898

Last change on this file since a762898 was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 38.2 KB
Line 
1"use strict";
2var __create = Object.create;
3var __defProp = Object.defineProperty;
4var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5var __getOwnPropNames = Object.getOwnPropertyNames;
6var __getProtoOf = Object.getPrototypeOf;
7var __hasOwnProp = Object.prototype.hasOwnProperty;
8var __export = (target, all) => {
9 for (var name in all)
10 __defProp(target, name, { get: all[name], enumerable: true });
11};
12var __copyProps = (to, from, except, desc) => {
13 if (from && typeof from === "object" || typeof from === "function") {
14 for (let key of __getOwnPropNames(from))
15 if (!__hasOwnProp.call(to, key) && key !== except)
16 __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17 }
18 return to;
19};
20var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21 // If the importer is in node compatibility mode or this is not an ESM
22 // file that has been converted to a CommonJS file using a Babel-
23 // compatible transform (i.e. "__esModule" has not been set), then set
24 // "default" to the CommonJS "module.exports" for node compatibility.
25 isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26 mod
27));
28var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
30// src/index.ts
31var src_exports = {};
32__export(src_exports, {
33 Provider: () => Provider_default,
34 ReactReduxContext: () => ReactReduxContext,
35 batch: () => batch,
36 connect: () => connect_default,
37 createDispatchHook: () => createDispatchHook,
38 createSelectorHook: () => createSelectorHook,
39 createStoreHook: () => createStoreHook,
40 shallowEqual: () => shallowEqual,
41 useDispatch: () => useDispatch,
42 useSelector: () => useSelector,
43 useStore: () => useStore
44});
45module.exports = __toCommonJS(src_exports);
46
47// src/utils/react.ts
48var React = __toESM(require("react"));
49
50// src/utils/react-is.ts
51var IS_REACT_19 = /* @__PURE__ */ React.version.startsWith("19");
52var REACT_ELEMENT_TYPE = /* @__PURE__ */ Symbol.for(
53 IS_REACT_19 ? "react.transitional.element" : "react.element"
54);
55var REACT_PORTAL_TYPE = /* @__PURE__ */ Symbol.for("react.portal");
56var REACT_FRAGMENT_TYPE = /* @__PURE__ */ Symbol.for("react.fragment");
57var REACT_STRICT_MODE_TYPE = /* @__PURE__ */ Symbol.for("react.strict_mode");
58var REACT_PROFILER_TYPE = /* @__PURE__ */ Symbol.for("react.profiler");
59var REACT_CONSUMER_TYPE = /* @__PURE__ */ Symbol.for("react.consumer");
60var REACT_CONTEXT_TYPE = /* @__PURE__ */ Symbol.for("react.context");
61var REACT_FORWARD_REF_TYPE = /* @__PURE__ */ Symbol.for("react.forward_ref");
62var REACT_SUSPENSE_TYPE = /* @__PURE__ */ Symbol.for("react.suspense");
63var REACT_SUSPENSE_LIST_TYPE = /* @__PURE__ */ Symbol.for(
64 "react.suspense_list"
65);
66var REACT_MEMO_TYPE = /* @__PURE__ */ Symbol.for("react.memo");
67var REACT_LAZY_TYPE = /* @__PURE__ */ Symbol.for("react.lazy");
68var REACT_OFFSCREEN_TYPE = /* @__PURE__ */ Symbol.for("react.offscreen");
69var REACT_CLIENT_REFERENCE = /* @__PURE__ */ Symbol.for(
70 "react.client.reference"
71);
72var ForwardRef = REACT_FORWARD_REF_TYPE;
73var Memo = REACT_MEMO_TYPE;
74function isValidElementType(type) {
75 return typeof type === "string" || typeof type === "function" || type === REACT_FRAGMENT_TYPE || type === REACT_PROFILER_TYPE || type === REACT_STRICT_MODE_TYPE || type === REACT_SUSPENSE_TYPE || type === REACT_SUSPENSE_LIST_TYPE || type === REACT_OFFSCREEN_TYPE || typeof type === "object" && type !== null && (type.$$typeof === REACT_LAZY_TYPE || type.$$typeof === REACT_MEMO_TYPE || type.$$typeof === REACT_CONTEXT_TYPE || type.$$typeof === REACT_CONSUMER_TYPE || type.$$typeof === REACT_FORWARD_REF_TYPE || type.$$typeof === REACT_CLIENT_REFERENCE || type.getModuleId !== void 0) ? true : false;
76}
77function typeOf(object) {
78 if (typeof object === "object" && object !== null) {
79 const { $$typeof } = object;
80 switch ($$typeof) {
81 case REACT_ELEMENT_TYPE:
82 switch (object = object.type, object) {
83 case REACT_FRAGMENT_TYPE:
84 case REACT_PROFILER_TYPE:
85 case REACT_STRICT_MODE_TYPE:
86 case REACT_SUSPENSE_TYPE:
87 case REACT_SUSPENSE_LIST_TYPE:
88 return object;
89 default:
90 switch (object = object && object.$$typeof, object) {
91 case REACT_CONTEXT_TYPE:
92 case REACT_FORWARD_REF_TYPE:
93 case REACT_LAZY_TYPE:
94 case REACT_MEMO_TYPE:
95 return object;
96 case REACT_CONSUMER_TYPE:
97 return object;
98 default:
99 return $$typeof;
100 }
101 }
102 case REACT_PORTAL_TYPE:
103 return $$typeof;
104 }
105 }
106}
107function isContextConsumer(object) {
108 return IS_REACT_19 ? typeOf(object) === REACT_CONSUMER_TYPE : typeOf(object) === REACT_CONTEXT_TYPE;
109}
110function isMemo(object) {
111 return typeOf(object) === REACT_MEMO_TYPE;
112}
113
114// src/utils/warning.ts
115function warning(message) {
116 if (typeof console !== "undefined" && typeof console.error === "function") {
117 console.error(message);
118 }
119 try {
120 throw new Error(message);
121 } catch (e) {
122 }
123}
124
125// src/connect/verifySubselectors.ts
126function verify(selector, methodName) {
127 if (!selector) {
128 throw new Error(`Unexpected value for ${methodName} in connect.`);
129 } else if (methodName === "mapStateToProps" || methodName === "mapDispatchToProps") {
130 if (!Object.prototype.hasOwnProperty.call(selector, "dependsOnOwnProps")) {
131 warning(
132 `The selector for ${methodName} of connect did not specify a value for dependsOnOwnProps.`
133 );
134 }
135 }
136}
137function verifySubselectors(mapStateToProps, mapDispatchToProps, mergeProps) {
138 verify(mapStateToProps, "mapStateToProps");
139 verify(mapDispatchToProps, "mapDispatchToProps");
140 verify(mergeProps, "mergeProps");
141}
142
143// src/connect/selectorFactory.ts
144function pureFinalPropsSelectorFactory(mapStateToProps, mapDispatchToProps, mergeProps, dispatch, {
145 areStatesEqual,
146 areOwnPropsEqual,
147 areStatePropsEqual
148}) {
149 let hasRunAtLeastOnce = false;
150 let state;
151 let ownProps;
152 let stateProps;
153 let dispatchProps;
154 let mergedProps;
155 function handleFirstCall(firstState, firstOwnProps) {
156 state = firstState;
157 ownProps = firstOwnProps;
158 stateProps = mapStateToProps(state, ownProps);
159 dispatchProps = mapDispatchToProps(dispatch, ownProps);
160 mergedProps = mergeProps(stateProps, dispatchProps, ownProps);
161 hasRunAtLeastOnce = true;
162 return mergedProps;
163 }
164 function handleNewPropsAndNewState() {
165 stateProps = mapStateToProps(state, ownProps);
166 if (mapDispatchToProps.dependsOnOwnProps)
167 dispatchProps = mapDispatchToProps(dispatch, ownProps);
168 mergedProps = mergeProps(stateProps, dispatchProps, ownProps);
169 return mergedProps;
170 }
171 function handleNewProps() {
172 if (mapStateToProps.dependsOnOwnProps)
173 stateProps = mapStateToProps(state, ownProps);
174 if (mapDispatchToProps.dependsOnOwnProps)
175 dispatchProps = mapDispatchToProps(dispatch, ownProps);
176 mergedProps = mergeProps(stateProps, dispatchProps, ownProps);
177 return mergedProps;
178 }
179 function handleNewState() {
180 const nextStateProps = mapStateToProps(state, ownProps);
181 const statePropsChanged = !areStatePropsEqual(nextStateProps, stateProps);
182 stateProps = nextStateProps;
183 if (statePropsChanged)
184 mergedProps = mergeProps(stateProps, dispatchProps, ownProps);
185 return mergedProps;
186 }
187 function handleSubsequentCalls(nextState, nextOwnProps) {
188 const propsChanged = !areOwnPropsEqual(nextOwnProps, ownProps);
189 const stateChanged = !areStatesEqual(
190 nextState,
191 state,
192 nextOwnProps,
193 ownProps
194 );
195 state = nextState;
196 ownProps = nextOwnProps;
197 if (propsChanged && stateChanged) return handleNewPropsAndNewState();
198 if (propsChanged) return handleNewProps();
199 if (stateChanged) return handleNewState();
200 return mergedProps;
201 }
202 return function pureFinalPropsSelector(nextState, nextOwnProps) {
203 return hasRunAtLeastOnce ? handleSubsequentCalls(nextState, nextOwnProps) : handleFirstCall(nextState, nextOwnProps);
204 };
205}
206function finalPropsSelectorFactory(dispatch, {
207 initMapStateToProps,
208 initMapDispatchToProps,
209 initMergeProps,
210 ...options
211}) {
212 const mapStateToProps = initMapStateToProps(dispatch, options);
213 const mapDispatchToProps = initMapDispatchToProps(dispatch, options);
214 const mergeProps = initMergeProps(dispatch, options);
215 if (true) {
216 verifySubselectors(mapStateToProps, mapDispatchToProps, mergeProps);
217 }
218 return pureFinalPropsSelectorFactory(mapStateToProps, mapDispatchToProps, mergeProps, dispatch, options);
219}
220
221// src/utils/bindActionCreators.ts
222function bindActionCreators(actionCreators, dispatch) {
223 const boundActionCreators = {};
224 for (const key in actionCreators) {
225 const actionCreator = actionCreators[key];
226 if (typeof actionCreator === "function") {
227 boundActionCreators[key] = (...args) => dispatch(actionCreator(...args));
228 }
229 }
230 return boundActionCreators;
231}
232
233// src/utils/isPlainObject.ts
234function isPlainObject(obj) {
235 if (typeof obj !== "object" || obj === null) return false;
236 const proto = Object.getPrototypeOf(obj);
237 if (proto === null) return true;
238 let baseProto = proto;
239 while (Object.getPrototypeOf(baseProto) !== null) {
240 baseProto = Object.getPrototypeOf(baseProto);
241 }
242 return proto === baseProto;
243}
244
245// src/utils/verifyPlainObject.ts
246function verifyPlainObject(value, displayName, methodName) {
247 if (!isPlainObject(value)) {
248 warning(
249 `${methodName}() in ${displayName} must return a plain object. Instead received ${value}.`
250 );
251 }
252}
253
254// src/connect/wrapMapToProps.ts
255function wrapMapToPropsConstant(getConstant) {
256 return function initConstantSelector(dispatch) {
257 const constant = getConstant(dispatch);
258 function constantSelector() {
259 return constant;
260 }
261 constantSelector.dependsOnOwnProps = false;
262 return constantSelector;
263 };
264}
265function getDependsOnOwnProps(mapToProps) {
266 return mapToProps.dependsOnOwnProps ? Boolean(mapToProps.dependsOnOwnProps) : mapToProps.length !== 1;
267}
268function wrapMapToPropsFunc(mapToProps, methodName) {
269 return function initProxySelector(dispatch, { displayName }) {
270 const proxy = function mapToPropsProxy(stateOrDispatch, ownProps) {
271 return proxy.dependsOnOwnProps ? proxy.mapToProps(stateOrDispatch, ownProps) : proxy.mapToProps(stateOrDispatch, void 0);
272 };
273 proxy.dependsOnOwnProps = true;
274 proxy.mapToProps = function detectFactoryAndVerify(stateOrDispatch, ownProps) {
275 proxy.mapToProps = mapToProps;
276 proxy.dependsOnOwnProps = getDependsOnOwnProps(mapToProps);
277 let props = proxy(stateOrDispatch, ownProps);
278 if (typeof props === "function") {
279 proxy.mapToProps = props;
280 proxy.dependsOnOwnProps = getDependsOnOwnProps(props);
281 props = proxy(stateOrDispatch, ownProps);
282 }
283 if (true)
284 verifyPlainObject(props, displayName, methodName);
285 return props;
286 };
287 return proxy;
288 };
289}
290
291// src/connect/invalidArgFactory.ts
292function createInvalidArgFactory(arg, name) {
293 return (dispatch, options) => {
294 throw new Error(
295 `Invalid value of type ${typeof arg} for ${name} argument when connecting component ${options.wrappedComponentName}.`
296 );
297 };
298}
299
300// src/connect/mapDispatchToProps.ts
301function mapDispatchToPropsFactory(mapDispatchToProps) {
302 return mapDispatchToProps && typeof mapDispatchToProps === "object" ? wrapMapToPropsConstant(
303 (dispatch) => (
304 // @ts-ignore
305 bindActionCreators(mapDispatchToProps, dispatch)
306 )
307 ) : !mapDispatchToProps ? wrapMapToPropsConstant((dispatch) => ({
308 dispatch
309 })) : typeof mapDispatchToProps === "function" ? (
310 // @ts-ignore
311 wrapMapToPropsFunc(mapDispatchToProps, "mapDispatchToProps")
312 ) : createInvalidArgFactory(mapDispatchToProps, "mapDispatchToProps");
313}
314
315// src/connect/mapStateToProps.ts
316function mapStateToPropsFactory(mapStateToProps) {
317 return !mapStateToProps ? wrapMapToPropsConstant(() => ({})) : typeof mapStateToProps === "function" ? (
318 // @ts-ignore
319 wrapMapToPropsFunc(mapStateToProps, "mapStateToProps")
320 ) : createInvalidArgFactory(mapStateToProps, "mapStateToProps");
321}
322
323// src/connect/mergeProps.ts
324function defaultMergeProps(stateProps, dispatchProps, ownProps) {
325 return { ...ownProps, ...stateProps, ...dispatchProps };
326}
327function wrapMergePropsFunc(mergeProps) {
328 return function initMergePropsProxy(dispatch, { displayName, areMergedPropsEqual }) {
329 let hasRunOnce = false;
330 let mergedProps;
331 return function mergePropsProxy(stateProps, dispatchProps, ownProps) {
332 const nextMergedProps = mergeProps(stateProps, dispatchProps, ownProps);
333 if (hasRunOnce) {
334 if (!areMergedPropsEqual(nextMergedProps, mergedProps))
335 mergedProps = nextMergedProps;
336 } else {
337 hasRunOnce = true;
338 mergedProps = nextMergedProps;
339 if (true)
340 verifyPlainObject(mergedProps, displayName, "mergeProps");
341 }
342 return mergedProps;
343 };
344 };
345}
346function mergePropsFactory(mergeProps) {
347 return !mergeProps ? () => defaultMergeProps : typeof mergeProps === "function" ? wrapMergePropsFunc(mergeProps) : createInvalidArgFactory(mergeProps, "mergeProps");
348}
349
350// src/utils/batch.ts
351function defaultNoopBatch(callback) {
352 callback();
353}
354
355// src/utils/Subscription.ts
356function createListenerCollection() {
357 let first = null;
358 let last = null;
359 return {
360 clear() {
361 first = null;
362 last = null;
363 },
364 notify() {
365 defaultNoopBatch(() => {
366 let listener = first;
367 while (listener) {
368 listener.callback();
369 listener = listener.next;
370 }
371 });
372 },
373 get() {
374 const listeners = [];
375 let listener = first;
376 while (listener) {
377 listeners.push(listener);
378 listener = listener.next;
379 }
380 return listeners;
381 },
382 subscribe(callback) {
383 let isSubscribed = true;
384 const listener = last = {
385 callback,
386 next: null,
387 prev: last
388 };
389 if (listener.prev) {
390 listener.prev.next = listener;
391 } else {
392 first = listener;
393 }
394 return function unsubscribe() {
395 if (!isSubscribed || first === null) return;
396 isSubscribed = false;
397 if (listener.next) {
398 listener.next.prev = listener.prev;
399 } else {
400 last = listener.prev;
401 }
402 if (listener.prev) {
403 listener.prev.next = listener.next;
404 } else {
405 first = listener.next;
406 }
407 };
408 }
409 };
410}
411var nullListeners = {
412 notify() {
413 },
414 get: () => []
415};
416function createSubscription(store, parentSub) {
417 let unsubscribe;
418 let listeners = nullListeners;
419 let subscriptionsAmount = 0;
420 let selfSubscribed = false;
421 function addNestedSub(listener) {
422 trySubscribe();
423 const cleanupListener = listeners.subscribe(listener);
424 let removed = false;
425 return () => {
426 if (!removed) {
427 removed = true;
428 cleanupListener();
429 tryUnsubscribe();
430 }
431 };
432 }
433 function notifyNestedSubs() {
434 listeners.notify();
435 }
436 function handleChangeWrapper() {
437 if (subscription.onStateChange) {
438 subscription.onStateChange();
439 }
440 }
441 function isSubscribed() {
442 return selfSubscribed;
443 }
444 function trySubscribe() {
445 subscriptionsAmount++;
446 if (!unsubscribe) {
447 unsubscribe = parentSub ? parentSub.addNestedSub(handleChangeWrapper) : store.subscribe(handleChangeWrapper);
448 listeners = createListenerCollection();
449 }
450 }
451 function tryUnsubscribe() {
452 subscriptionsAmount--;
453 if (unsubscribe && subscriptionsAmount === 0) {
454 unsubscribe();
455 unsubscribe = void 0;
456 listeners.clear();
457 listeners = nullListeners;
458 }
459 }
460 function trySubscribeSelf() {
461 if (!selfSubscribed) {
462 selfSubscribed = true;
463 trySubscribe();
464 }
465 }
466 function tryUnsubscribeSelf() {
467 if (selfSubscribed) {
468 selfSubscribed = false;
469 tryUnsubscribe();
470 }
471 }
472 const subscription = {
473 addNestedSub,
474 notifyNestedSubs,
475 handleChangeWrapper,
476 isSubscribed,
477 trySubscribe: trySubscribeSelf,
478 tryUnsubscribe: tryUnsubscribeSelf,
479 getListeners: () => listeners
480 };
481 return subscription;
482}
483
484// src/utils/useIsomorphicLayoutEffect.ts
485var canUseDOM = () => !!(typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement !== "undefined");
486var isDOM = /* @__PURE__ */ canUseDOM();
487var isRunningInReactNative = () => typeof navigator !== "undefined" && navigator.product === "ReactNative";
488var isReactNative = /* @__PURE__ */ isRunningInReactNative();
489var getUseIsomorphicLayoutEffect = () => isDOM || isReactNative ? React.useLayoutEffect : React.useEffect;
490var useIsomorphicLayoutEffect = /* @__PURE__ */ getUseIsomorphicLayoutEffect();
491
492// src/utils/shallowEqual.ts
493function is(x, y) {
494 if (x === y) {
495 return x !== 0 || y !== 0 || 1 / x === 1 / y;
496 } else {
497 return x !== x && y !== y;
498 }
499}
500function shallowEqual(objA, objB) {
501 if (is(objA, objB)) return true;
502 if (typeof objA !== "object" || objA === null || typeof objB !== "object" || objB === null) {
503 return false;
504 }
505 const keysA = Object.keys(objA);
506 const keysB = Object.keys(objB);
507 if (keysA.length !== keysB.length) return false;
508 for (let i = 0; i < keysA.length; i++) {
509 if (!Object.prototype.hasOwnProperty.call(objB, keysA[i]) || !is(objA[keysA[i]], objB[keysA[i]])) {
510 return false;
511 }
512 }
513 return true;
514}
515
516// src/utils/hoistStatics.ts
517var REACT_STATICS = {
518 childContextTypes: true,
519 contextType: true,
520 contextTypes: true,
521 defaultProps: true,
522 displayName: true,
523 getDefaultProps: true,
524 getDerivedStateFromError: true,
525 getDerivedStateFromProps: true,
526 mixins: true,
527 propTypes: true,
528 type: true
529};
530var KNOWN_STATICS = {
531 name: true,
532 length: true,
533 prototype: true,
534 caller: true,
535 callee: true,
536 arguments: true,
537 arity: true
538};
539var FORWARD_REF_STATICS = {
540 $$typeof: true,
541 render: true,
542 defaultProps: true,
543 displayName: true,
544 propTypes: true
545};
546var MEMO_STATICS = {
547 $$typeof: true,
548 compare: true,
549 defaultProps: true,
550 displayName: true,
551 propTypes: true,
552 type: true
553};
554var TYPE_STATICS = {
555 [ForwardRef]: FORWARD_REF_STATICS,
556 [Memo]: MEMO_STATICS
557};
558function getStatics(component) {
559 if (isMemo(component)) {
560 return MEMO_STATICS;
561 }
562 return TYPE_STATICS[component["$$typeof"]] || REACT_STATICS;
563}
564var defineProperty = Object.defineProperty;
565var getOwnPropertyNames = Object.getOwnPropertyNames;
566var getOwnPropertySymbols = Object.getOwnPropertySymbols;
567var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
568var getPrototypeOf = Object.getPrototypeOf;
569var objectPrototype = Object.prototype;
570function hoistNonReactStatics(targetComponent, sourceComponent) {
571 if (typeof sourceComponent !== "string") {
572 if (objectPrototype) {
573 const inheritedComponent = getPrototypeOf(sourceComponent);
574 if (inheritedComponent && inheritedComponent !== objectPrototype) {
575 hoistNonReactStatics(targetComponent, inheritedComponent);
576 }
577 }
578 let keys = getOwnPropertyNames(sourceComponent);
579 if (getOwnPropertySymbols) {
580 keys = keys.concat(getOwnPropertySymbols(sourceComponent));
581 }
582 const targetStatics = getStatics(targetComponent);
583 const sourceStatics = getStatics(sourceComponent);
584 for (let i = 0; i < keys.length; ++i) {
585 const key = keys[i];
586 if (!KNOWN_STATICS[key] && !(sourceStatics && sourceStatics[key]) && !(targetStatics && targetStatics[key])) {
587 const descriptor = getOwnPropertyDescriptor(sourceComponent, key);
588 try {
589 defineProperty(targetComponent, key, descriptor);
590 } catch (e) {
591 }
592 }
593 }
594 }
595 return targetComponent;
596}
597
598// src/components/Context.ts
599var ContextKey = /* @__PURE__ */ Symbol.for(`react-redux-context`);
600var gT = typeof globalThis !== "undefined" ? globalThis : (
601 /* fall back to a per-module scope (pre-8.1 behaviour) if `globalThis` is not available */
602 {}
603);
604function getContext() {
605 if (!React.createContext) return {};
606 const contextMap = gT[ContextKey] ??= /* @__PURE__ */ new Map();
607 let realContext = contextMap.get(React.createContext);
608 if (!realContext) {
609 realContext = React.createContext(
610 null
611 );
612 if (true) {
613 realContext.displayName = "ReactRedux";
614 }
615 contextMap.set(React.createContext, realContext);
616 }
617 return realContext;
618}
619var ReactReduxContext = /* @__PURE__ */ getContext();
620
621// src/components/connect.tsx
622var NO_SUBSCRIPTION_ARRAY = [null, null];
623var stringifyComponent = (Comp) => {
624 try {
625 return JSON.stringify(Comp);
626 } catch (err) {
627 return String(Comp);
628 }
629};
630function useIsomorphicLayoutEffectWithArgs(effectFunc, effectArgs, dependencies) {
631 useIsomorphicLayoutEffect(() => effectFunc(...effectArgs), dependencies);
632}
633function captureWrapperProps(lastWrapperProps, lastChildProps, renderIsScheduled, wrapperProps, childPropsFromStoreUpdate, notifyNestedSubs) {
634 lastWrapperProps.current = wrapperProps;
635 renderIsScheduled.current = false;
636 if (childPropsFromStoreUpdate.current) {
637 childPropsFromStoreUpdate.current = null;
638 notifyNestedSubs();
639 }
640}
641function subscribeUpdates(shouldHandleStateChanges, store, subscription, childPropsSelector, lastWrapperProps, lastChildProps, renderIsScheduled, isMounted, childPropsFromStoreUpdate, notifyNestedSubs, additionalSubscribeListener) {
642 if (!shouldHandleStateChanges) return () => {
643 };
644 let didUnsubscribe = false;
645 let lastThrownError = null;
646 const checkForUpdates = () => {
647 if (didUnsubscribe || !isMounted.current) {
648 return;
649 }
650 const latestStoreState = store.getState();
651 let newChildProps, error;
652 try {
653 newChildProps = childPropsSelector(
654 latestStoreState,
655 lastWrapperProps.current
656 );
657 } catch (e) {
658 error = e;
659 lastThrownError = e;
660 }
661 if (!error) {
662 lastThrownError = null;
663 }
664 if (newChildProps === lastChildProps.current) {
665 if (!renderIsScheduled.current) {
666 notifyNestedSubs();
667 }
668 } else {
669 lastChildProps.current = newChildProps;
670 childPropsFromStoreUpdate.current = newChildProps;
671 renderIsScheduled.current = true;
672 additionalSubscribeListener();
673 }
674 };
675 subscription.onStateChange = checkForUpdates;
676 subscription.trySubscribe();
677 checkForUpdates();
678 const unsubscribeWrapper = () => {
679 didUnsubscribe = true;
680 subscription.tryUnsubscribe();
681 subscription.onStateChange = null;
682 if (lastThrownError) {
683 throw lastThrownError;
684 }
685 };
686 return unsubscribeWrapper;
687}
688function strictEqual(a, b) {
689 return a === b;
690}
691var hasWarnedAboutDeprecatedPureOption = false;
692function connect(mapStateToProps, mapDispatchToProps, mergeProps, {
693 // The `pure` option has been removed, so TS doesn't like us destructuring this to check its existence.
694 // @ts-ignore
695 pure,
696 areStatesEqual = strictEqual,
697 areOwnPropsEqual = shallowEqual,
698 areStatePropsEqual = shallowEqual,
699 areMergedPropsEqual = shallowEqual,
700 // use React's forwardRef to expose a ref of the wrapped component
701 forwardRef = false,
702 // the context consumer to use
703 context = ReactReduxContext
704} = {}) {
705 if (true) {
706 if (pure !== void 0 && !hasWarnedAboutDeprecatedPureOption) {
707 hasWarnedAboutDeprecatedPureOption = true;
708 warning(
709 'The `pure` option has been removed. `connect` is now always a "pure/memoized" component'
710 );
711 }
712 }
713 const Context = context;
714 const initMapStateToProps = mapStateToPropsFactory(mapStateToProps);
715 const initMapDispatchToProps = mapDispatchToPropsFactory(mapDispatchToProps);
716 const initMergeProps = mergePropsFactory(mergeProps);
717 const shouldHandleStateChanges = Boolean(mapStateToProps);
718 const wrapWithConnect = (WrappedComponent) => {
719 if (true) {
720 const isValid = /* @__PURE__ */ isValidElementType(WrappedComponent);
721 if (!isValid)
722 throw new Error(
723 `You must pass a component to the function returned by connect. Instead received ${stringifyComponent(
724 WrappedComponent
725 )}`
726 );
727 }
728 const wrappedComponentName = WrappedComponent.displayName || WrappedComponent.name || "Component";
729 const displayName = `Connect(${wrappedComponentName})`;
730 const selectorFactoryOptions = {
731 shouldHandleStateChanges,
732 displayName,
733 wrappedComponentName,
734 WrappedComponent,
735 // @ts-ignore
736 initMapStateToProps,
737 initMapDispatchToProps,
738 initMergeProps,
739 areStatesEqual,
740 areStatePropsEqual,
741 areOwnPropsEqual,
742 areMergedPropsEqual
743 };
744 function ConnectFunction(props) {
745 const [propsContext, reactReduxForwardedRef, wrapperProps] = React.useMemo(() => {
746 const { reactReduxForwardedRef: reactReduxForwardedRef2, ...wrapperProps2 } = props;
747 return [props.context, reactReduxForwardedRef2, wrapperProps2];
748 }, [props]);
749 const ContextToUse = React.useMemo(() => {
750 let ResultContext = Context;
751 if (propsContext?.Consumer) {
752 if (true) {
753 const isValid = /* @__PURE__ */ isContextConsumer(
754 // @ts-ignore
755 /* @__PURE__ */ React.createElement(propsContext.Consumer, null)
756 );
757 if (!isValid) {
758 throw new Error(
759 "You must pass a valid React context consumer as `props.context`"
760 );
761 }
762 ResultContext = propsContext;
763 }
764 }
765 return ResultContext;
766 }, [propsContext, Context]);
767 const contextValue = React.useContext(ContextToUse);
768 const didStoreComeFromProps = Boolean(props.store) && Boolean(props.store.getState) && Boolean(props.store.dispatch);
769 const didStoreComeFromContext = Boolean(contextValue) && Boolean(contextValue.store);
770 if (!didStoreComeFromProps && !didStoreComeFromContext) {
771 throw new Error(
772 `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.`
773 );
774 }
775 const store = didStoreComeFromProps ? props.store : contextValue.store;
776 const getServerState = didStoreComeFromContext ? contextValue.getServerState : store.getState;
777 const childPropsSelector = React.useMemo(() => {
778 return finalPropsSelectorFactory(store.dispatch, selectorFactoryOptions);
779 }, [store]);
780 const [subscription, notifyNestedSubs] = React.useMemo(() => {
781 if (!shouldHandleStateChanges) return NO_SUBSCRIPTION_ARRAY;
782 const subscription2 = createSubscription(
783 store,
784 didStoreComeFromProps ? void 0 : contextValue.subscription
785 );
786 const notifyNestedSubs2 = subscription2.notifyNestedSubs.bind(subscription2);
787 return [subscription2, notifyNestedSubs2];
788 }, [store, didStoreComeFromProps, contextValue]);
789 const overriddenContextValue = React.useMemo(() => {
790 if (didStoreComeFromProps) {
791 return contextValue;
792 }
793 return {
794 ...contextValue,
795 subscription
796 };
797 }, [didStoreComeFromProps, contextValue, subscription]);
798 const lastChildProps = React.useRef(void 0);
799 const lastWrapperProps = React.useRef(wrapperProps);
800 const childPropsFromStoreUpdate = React.useRef(void 0);
801 const renderIsScheduled = React.useRef(false);
802 const isMounted = React.useRef(false);
803 const latestSubscriptionCallbackError = React.useRef(
804 void 0
805 );
806 useIsomorphicLayoutEffect(() => {
807 isMounted.current = true;
808 return () => {
809 isMounted.current = false;
810 };
811 }, []);
812 const actualChildPropsSelector = React.useMemo(() => {
813 const selector = () => {
814 if (childPropsFromStoreUpdate.current && wrapperProps === lastWrapperProps.current) {
815 return childPropsFromStoreUpdate.current;
816 }
817 return childPropsSelector(store.getState(), wrapperProps);
818 };
819 return selector;
820 }, [store, wrapperProps]);
821 const subscribeForReact = React.useMemo(() => {
822 const subscribe = (reactListener) => {
823 if (!subscription) {
824 return () => {
825 };
826 }
827 return subscribeUpdates(
828 shouldHandleStateChanges,
829 store,
830 subscription,
831 // @ts-ignore
832 childPropsSelector,
833 lastWrapperProps,
834 lastChildProps,
835 renderIsScheduled,
836 isMounted,
837 childPropsFromStoreUpdate,
838 notifyNestedSubs,
839 reactListener
840 );
841 };
842 return subscribe;
843 }, [subscription]);
844 useIsomorphicLayoutEffectWithArgs(captureWrapperProps, [
845 lastWrapperProps,
846 lastChildProps,
847 renderIsScheduled,
848 wrapperProps,
849 childPropsFromStoreUpdate,
850 notifyNestedSubs
851 ]);
852 let actualChildProps;
853 try {
854 actualChildProps = React.useSyncExternalStore(
855 // TODO We're passing through a big wrapper that does a bunch of extra side effects besides subscribing
856 subscribeForReact,
857 // TODO This is incredibly hacky. We've already processed the store update and calculated new child props,
858 // TODO and we're just passing that through so it triggers a re-render for us rather than relying on `uSES`.
859 actualChildPropsSelector,
860 getServerState ? () => childPropsSelector(getServerState(), wrapperProps) : actualChildPropsSelector
861 );
862 } catch (err) {
863 if (latestSubscriptionCallbackError.current) {
864 ;
865 err.message += `
866The error may be correlated with this previous error:
867${latestSubscriptionCallbackError.current.stack}
868
869`;
870 }
871 throw err;
872 }
873 useIsomorphicLayoutEffect(() => {
874 latestSubscriptionCallbackError.current = void 0;
875 childPropsFromStoreUpdate.current = void 0;
876 lastChildProps.current = actualChildProps;
877 });
878 const renderedWrappedComponent = React.useMemo(() => {
879 return (
880 // @ts-ignore
881 /* @__PURE__ */ React.createElement(
882 WrappedComponent,
883 {
884 ...actualChildProps,
885 ref: reactReduxForwardedRef
886 }
887 )
888 );
889 }, [reactReduxForwardedRef, WrappedComponent, actualChildProps]);
890 const renderedChild = React.useMemo(() => {
891 if (shouldHandleStateChanges) {
892 return /* @__PURE__ */ React.createElement(ContextToUse.Provider, { value: overriddenContextValue }, renderedWrappedComponent);
893 }
894 return renderedWrappedComponent;
895 }, [ContextToUse, renderedWrappedComponent, overriddenContextValue]);
896 return renderedChild;
897 }
898 const _Connect = React.memo(ConnectFunction);
899 const Connect = _Connect;
900 Connect.WrappedComponent = WrappedComponent;
901 Connect.displayName = ConnectFunction.displayName = displayName;
902 if (forwardRef) {
903 const _forwarded = React.forwardRef(
904 function forwardConnectRef(props, ref) {
905 return /* @__PURE__ */ React.createElement(Connect, { ...props, reactReduxForwardedRef: ref });
906 }
907 );
908 const forwarded = _forwarded;
909 forwarded.displayName = displayName;
910 forwarded.WrappedComponent = WrappedComponent;
911 return /* @__PURE__ */ hoistNonReactStatics(forwarded, WrappedComponent);
912 }
913 return /* @__PURE__ */ hoistNonReactStatics(Connect, WrappedComponent);
914 };
915 return wrapWithConnect;
916}
917var connect_default = connect;
918
919// src/components/Provider.tsx
920function Provider(providerProps) {
921 const { children, context, serverState, store } = providerProps;
922 const contextValue = React.useMemo(() => {
923 const subscription = createSubscription(store);
924 const baseContextValue = {
925 store,
926 subscription,
927 getServerState: serverState ? () => serverState : void 0
928 };
929 if (false) {
930 return baseContextValue;
931 } else {
932 const { identityFunctionCheck = "once", stabilityCheck = "once" } = providerProps;
933 return /* @__PURE__ */ Object.assign(baseContextValue, {
934 stabilityCheck,
935 identityFunctionCheck
936 });
937 }
938 }, [store, serverState]);
939 const previousState = React.useMemo(() => store.getState(), [store]);
940 useIsomorphicLayoutEffect(() => {
941 const { subscription } = contextValue;
942 subscription.onStateChange = subscription.notifyNestedSubs;
943 subscription.trySubscribe();
944 if (previousState !== store.getState()) {
945 subscription.notifyNestedSubs();
946 }
947 return () => {
948 subscription.tryUnsubscribe();
949 subscription.onStateChange = void 0;
950 };
951 }, [contextValue, previousState]);
952 const Context = context || ReactReduxContext;
953 return /* @__PURE__ */ React.createElement(Context.Provider, { value: contextValue }, children);
954}
955var Provider_default = Provider;
956
957// src/hooks/useReduxContext.ts
958function createReduxContextHook(context = ReactReduxContext) {
959 return function useReduxContext2() {
960 const contextValue = React.useContext(context);
961 if (!contextValue) {
962 throw new Error(
963 "could not find react-redux context value; please ensure the component is wrapped in a <Provider>"
964 );
965 }
966 return contextValue;
967 };
968}
969var useReduxContext = /* @__PURE__ */ createReduxContextHook();
970
971// src/hooks/useStore.ts
972function createStoreHook(context = ReactReduxContext) {
973 const useReduxContext2 = context === ReactReduxContext ? useReduxContext : (
974 // @ts-ignore
975 createReduxContextHook(context)
976 );
977 const useStore2 = () => {
978 const { store } = useReduxContext2();
979 return store;
980 };
981 Object.assign(useStore2, {
982 withTypes: () => useStore2
983 });
984 return useStore2;
985}
986var useStore = /* @__PURE__ */ createStoreHook();
987
988// src/hooks/useDispatch.ts
989function createDispatchHook(context = ReactReduxContext) {
990 const useStore2 = context === ReactReduxContext ? useStore : createStoreHook(context);
991 const useDispatch2 = () => {
992 const store = useStore2();
993 return store.dispatch;
994 };
995 Object.assign(useDispatch2, {
996 withTypes: () => useDispatch2
997 });
998 return useDispatch2;
999}
1000var useDispatch = /* @__PURE__ */ createDispatchHook();
1001
1002// src/hooks/useSelector.ts
1003var import_with_selector = require("use-sync-external-store/with-selector.js");
1004var refEquality = (a, b) => a === b;
1005function createSelectorHook(context = ReactReduxContext) {
1006 const useReduxContext2 = context === ReactReduxContext ? useReduxContext : createReduxContextHook(context);
1007 const useSelector2 = (selector, equalityFnOrOptions = {}) => {
1008 const { equalityFn = refEquality } = typeof equalityFnOrOptions === "function" ? { equalityFn: equalityFnOrOptions } : equalityFnOrOptions;
1009 if (true) {
1010 if (!selector) {
1011 throw new Error(`You must pass a selector to useSelector`);
1012 }
1013 if (typeof selector !== "function") {
1014 throw new Error(`You must pass a function as a selector to useSelector`);
1015 }
1016 if (typeof equalityFn !== "function") {
1017 throw new Error(
1018 `You must pass a function as an equality function to useSelector`
1019 );
1020 }
1021 }
1022 const reduxContext = useReduxContext2();
1023 const { store, subscription, getServerState } = reduxContext;
1024 const firstRun = React.useRef(true);
1025 const wrappedSelector = React.useCallback(
1026 {
1027 [selector.name](state) {
1028 const selected = selector(state);
1029 if (true) {
1030 const { devModeChecks = {} } = typeof equalityFnOrOptions === "function" ? {} : equalityFnOrOptions;
1031 const { identityFunctionCheck, stabilityCheck } = reduxContext;
1032 const {
1033 identityFunctionCheck: finalIdentityFunctionCheck,
1034 stabilityCheck: finalStabilityCheck
1035 } = {
1036 stabilityCheck,
1037 identityFunctionCheck,
1038 ...devModeChecks
1039 };
1040 if (finalStabilityCheck === "always" || finalStabilityCheck === "once" && firstRun.current) {
1041 const toCompare = selector(state);
1042 if (!equalityFn(selected, toCompare)) {
1043 let stack = void 0;
1044 try {
1045 throw new Error();
1046 } catch (e) {
1047 ;
1048 ({ stack } = e);
1049 }
1050 console.warn(
1051 "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",
1052 {
1053 state,
1054 selected,
1055 selected2: toCompare,
1056 stack
1057 }
1058 );
1059 }
1060 }
1061 if (finalIdentityFunctionCheck === "always" || finalIdentityFunctionCheck === "once" && firstRun.current) {
1062 if (selected === state) {
1063 let stack = void 0;
1064 try {
1065 throw new Error();
1066 } catch (e) {
1067 ;
1068 ({ stack } = e);
1069 }
1070 console.warn(
1071 "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.",
1072 { stack }
1073 );
1074 }
1075 }
1076 if (firstRun.current) firstRun.current = false;
1077 }
1078 return selected;
1079 }
1080 }[selector.name],
1081 [selector]
1082 );
1083 const selectedState = (0, import_with_selector.useSyncExternalStoreWithSelector)(
1084 subscription.addNestedSub,
1085 store.getState,
1086 getServerState || store.getState,
1087 wrappedSelector,
1088 equalityFn
1089 );
1090 React.useDebugValue(selectedState);
1091 return selectedState;
1092 };
1093 Object.assign(useSelector2, {
1094 withTypes: () => useSelector2
1095 });
1096 return useSelector2;
1097}
1098var useSelector = /* @__PURE__ */ createSelectorHook();
1099
1100// src/exports.ts
1101var batch = defaultNoopBatch;
1102// Annotate the CommonJS export names for ESM import in node:
11030 && (module.exports = {
1104 Provider,
1105 ReactReduxContext,
1106 batch,
1107 connect,
1108 createDispatchHook,
1109 createSelectorHook,
1110 createStoreHook,
1111 shallowEqual,
1112 useDispatch,
1113 useSelector,
1114 useStore
1115});
1116//# sourceMappingURL=react-redux.development.cjs.map
Note: See TracBrowser for help on using the repository browser.