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