>,\n {\n initMapStateToProps,\n initMapDispatchToProps,\n initMergeProps,\n ...options\n }: SelectorFactoryOptions<\n TStateProps,\n TOwnProps,\n TDispatchProps,\n TMergedProps,\n State\n >,\n) {\n const mapStateToProps = initMapStateToProps(dispatch, options)\n const mapDispatchToProps = initMapDispatchToProps(dispatch, options)\n const mergeProps = initMergeProps(dispatch, options)\n\n if (process.env.NODE_ENV !== 'production') {\n verifySubselectors(mapStateToProps, mapDispatchToProps, mergeProps)\n }\n\n return pureFinalPropsSelectorFactory<\n TStateProps,\n TOwnProps,\n TDispatchProps,\n TMergedProps,\n State\n >(mapStateToProps, mapDispatchToProps, mergeProps, dispatch, options)\n}\n","import type { ActionCreatorsMapObject, Dispatch, ActionCreator } from 'redux'\n\nimport type { FixTypeLater } from '../types'\nimport verifyPlainObject from '../utils/verifyPlainObject'\n\ntype AnyState = { [key: string]: any }\ntype StateOrDispatch = S | Dispatch\n\ntype AnyProps = { [key: string]: any }\n\nexport type MapToProps = {\n // eslint-disable-next-line no-unused-vars\n (stateOrDispatch: StateOrDispatch, ownProps?: P): FixTypeLater\n dependsOnOwnProps?: boolean\n}\n\nexport function wrapMapToPropsConstant(\n // * Note:\n // It seems that the dispatch argument\n // could be a dispatch function in some cases (ex: whenMapDispatchToPropsIsMissing)\n // and a state object in some others (ex: whenMapStateToPropsIsMissing)\n // eslint-disable-next-line no-unused-vars\n getConstant: (dispatch: Dispatch) =>\n | {\n dispatch?: Dispatch\n dependsOnOwnProps?: boolean\n }\n | ActionCreatorsMapObject\n | ActionCreator,\n) {\n return function initConstantSelector(dispatch: Dispatch) {\n const constant = getConstant(dispatch)\n\n function constantSelector() {\n return constant\n }\n constantSelector.dependsOnOwnProps = false\n return constantSelector\n }\n}\n\n// dependsOnOwnProps is used by createMapToPropsProxy to determine whether to pass props as args\n// to the mapToProps function being wrapped. It is also used by makePurePropsSelector to determine\n// whether mapToProps needs to be invoked when props have changed.\n//\n// A length of one signals that mapToProps does not depend on props from the parent component.\n// A length of zero is assumed to mean mapToProps is getting args via arguments or ...args and\n// therefore not reporting its length accurately..\n// TODO Can this get pulled out so that we can subscribe directly to the store if we don't need ownProps?\nexport function getDependsOnOwnProps(mapToProps: MapToProps) {\n return mapToProps.dependsOnOwnProps\n ? Boolean(mapToProps.dependsOnOwnProps)\n : mapToProps.length !== 1\n}\n\n// Used by whenMapStateToPropsIsFunction and whenMapDispatchToPropsIsFunction,\n// this function wraps mapToProps in a proxy function which does several things:\n//\n// * Detects whether the mapToProps function being called depends on props, which\n// is used by selectorFactory to decide if it should reinvoke on props changes.\n//\n// * On first call, handles mapToProps if returns another function, and treats that\n// new function as the true mapToProps for subsequent calls.\n//\n// * On first call, verifies the first result is a plain object, in order to warn\n// the developer that their mapToProps function is not returning a valid result.\n//\nexport function wrapMapToPropsFunc(\n mapToProps: MapToProps,\n methodName: string,\n) {\n return function initProxySelector(\n dispatch: Dispatch,\n { displayName }: { displayName: string },\n ) {\n const proxy = function mapToPropsProxy(\n stateOrDispatch: StateOrDispatch,\n ownProps?: P,\n ): MapToProps {\n return proxy.dependsOnOwnProps\n ? proxy.mapToProps(stateOrDispatch, ownProps)\n : proxy.mapToProps(stateOrDispatch, undefined)\n }\n\n // allow detectFactoryAndVerify to get ownProps\n proxy.dependsOnOwnProps = true\n\n proxy.mapToProps = function detectFactoryAndVerify(\n stateOrDispatch: StateOrDispatch,\n ownProps?: P,\n ): MapToProps {\n proxy.mapToProps = mapToProps\n proxy.dependsOnOwnProps = getDependsOnOwnProps(mapToProps)\n let props = proxy(stateOrDispatch, ownProps)\n\n if (typeof props === 'function') {\n proxy.mapToProps = props\n proxy.dependsOnOwnProps = getDependsOnOwnProps(props)\n props = proxy(stateOrDispatch, ownProps)\n }\n\n if (process.env.NODE_ENV !== 'production')\n verifyPlainObject(props, displayName, methodName)\n\n return props\n }\n\n return proxy\n }\n}\n","import type { Action, Dispatch } from 'redux'\n\nexport function createInvalidArgFactory(arg: unknown, name: string) {\n return (\n dispatch: Dispatch>,\n options: { readonly wrappedComponentName: string },\n ) => {\n throw new Error(\n `Invalid value of type ${typeof arg} for ${name} argument when connecting component ${\n options.wrappedComponentName\n }.`,\n )\n }\n}\n","import type { Action, Dispatch } from 'redux'\nimport verifyPlainObject from '../utils/verifyPlainObject'\nimport { createInvalidArgFactory } from './invalidArgFactory'\nimport type { MergeProps } from './selectorFactory'\nimport type { EqualityFn } from '../types'\n\nexport function defaultMergeProps<\n TStateProps,\n TDispatchProps,\n TOwnProps,\n TMergedProps,\n>(\n stateProps: TStateProps,\n dispatchProps: TDispatchProps,\n ownProps: TOwnProps,\n): TMergedProps {\n // @ts-ignore\n return { ...ownProps, ...stateProps, ...dispatchProps }\n}\n\nexport function wrapMergePropsFunc<\n TStateProps,\n TDispatchProps,\n TOwnProps,\n TMergedProps,\n>(\n mergeProps: MergeProps,\n): (\n dispatch: Dispatch>,\n options: {\n readonly displayName: string\n readonly areMergedPropsEqual: EqualityFn\n },\n) => MergeProps {\n return function initMergePropsProxy(\n dispatch,\n { displayName, areMergedPropsEqual },\n ) {\n let hasRunOnce = false\n let mergedProps: TMergedProps\n\n return function mergePropsProxy(\n stateProps: TStateProps,\n dispatchProps: TDispatchProps,\n ownProps: TOwnProps,\n ) {\n const nextMergedProps = mergeProps(stateProps, dispatchProps, ownProps)\n\n if (hasRunOnce) {\n if (!areMergedPropsEqual(nextMergedProps, mergedProps))\n mergedProps = nextMergedProps\n } else {\n hasRunOnce = true\n mergedProps = nextMergedProps\n\n if (process.env.NODE_ENV !== 'production')\n verifyPlainObject(mergedProps, displayName, 'mergeProps')\n }\n\n return mergedProps\n }\n }\n}\n\nexport function mergePropsFactory<\n TStateProps,\n TDispatchProps,\n TOwnProps,\n TMergedProps,\n>(\n mergeProps?: MergeProps,\n) {\n return !mergeProps\n ? () => defaultMergeProps\n : typeof mergeProps === 'function'\n ? wrapMergePropsFunc(mergeProps)\n : createInvalidArgFactory(mergeProps, 'mergeProps')\n}\n","// Default to a dummy \"batch\" implementation that just runs the callback\r\nexport function defaultNoopBatch(callback: () => void) {\r\n callback()\r\n}\r\n","import { defaultNoopBatch as batch } from './batch'\n\n// encapsulates the subscription logic for connecting a component to the redux store, as\n// well as nesting subscriptions of descendant components, so that we can ensure the\n// ancestor components re-render before descendants\n\ntype VoidFunc = () => void\n\ntype Listener = {\n callback: VoidFunc\n next: Listener | null\n prev: Listener | null\n}\n\nfunction createListenerCollection() {\n let first: Listener | null = null\n let last: Listener | null = null\n\n return {\n clear() {\n first = null\n last = null\n },\n\n notify() {\n batch(() => {\n let listener = first\n while (listener) {\n listener.callback()\n listener = listener.next\n }\n })\n },\n\n get() {\n const listeners: Listener[] = []\n let listener = first\n while (listener) {\n listeners.push(listener)\n listener = listener.next\n }\n return listeners\n },\n\n subscribe(callback: () => void) {\n let isSubscribed = true\n\n const listener: Listener = (last = {\n callback,\n next: null,\n prev: last,\n })\n\n if (listener.prev) {\n listener.prev.next = listener\n } else {\n first = listener\n }\n\n return function unsubscribe() {\n if (!isSubscribed || first === null) return\n isSubscribed = false\n\n if (listener.next) {\n listener.next.prev = listener.prev\n } else {\n last = listener.prev\n }\n if (listener.prev) {\n listener.prev.next = listener.next\n } else {\n first = listener.next\n }\n }\n },\n }\n}\n\ntype ListenerCollection = ReturnType\n\nexport interface Subscription {\n addNestedSub: (listener: VoidFunc) => VoidFunc\n notifyNestedSubs: VoidFunc\n handleChangeWrapper: VoidFunc\n isSubscribed: () => boolean\n onStateChange?: VoidFunc | null\n trySubscribe: VoidFunc\n tryUnsubscribe: VoidFunc\n getListeners: () => ListenerCollection\n}\n\nconst nullListeners = {\n notify() {},\n get: () => [],\n} as unknown as ListenerCollection\n\nexport function createSubscription(store: any, parentSub?: Subscription) {\n let unsubscribe: VoidFunc | undefined\n let listeners: ListenerCollection = nullListeners\n\n // Reasons to keep the subscription active\n let subscriptionsAmount = 0\n\n // Is this specific subscription subscribed (or only nested ones?)\n let selfSubscribed = false\n\n function addNestedSub(listener: () => void) {\n trySubscribe()\n\n const cleanupListener = listeners.subscribe(listener)\n\n // cleanup nested sub\n let removed = false\n return () => {\n if (!removed) {\n removed = true\n cleanupListener()\n tryUnsubscribe()\n }\n }\n }\n\n function notifyNestedSubs() {\n listeners.notify()\n }\n\n function handleChangeWrapper() {\n if (subscription.onStateChange) {\n subscription.onStateChange()\n }\n }\n\n function isSubscribed() {\n return selfSubscribed\n }\n\n function trySubscribe() {\n subscriptionsAmount++\n if (!unsubscribe) {\n unsubscribe = parentSub\n ? parentSub.addNestedSub(handleChangeWrapper)\n : store.subscribe(handleChangeWrapper)\n\n listeners = createListenerCollection()\n }\n }\n\n function tryUnsubscribe() {\n subscriptionsAmount--\n if (unsubscribe && subscriptionsAmount === 0) {\n unsubscribe()\n unsubscribe = undefined\n listeners.clear()\n listeners = nullListeners\n }\n }\n\n function trySubscribeSelf() {\n if (!selfSubscribed) {\n selfSubscribed = true\n trySubscribe()\n }\n }\n\n function tryUnsubscribeSelf() {\n if (selfSubscribed) {\n selfSubscribed = false\n tryUnsubscribe()\n }\n }\n\n const subscription: Subscription = {\n addNestedSub,\n notifyNestedSubs,\n handleChangeWrapper,\n isSubscribed,\n trySubscribe: trySubscribeSelf,\n tryUnsubscribe: tryUnsubscribeSelf,\n getListeners: () => listeners,\n }\n\n return subscription\n}\n","import { React } from '../utils/react'\n\n// React currently throws a warning when using useLayoutEffect on the server.\n// To get around it, we can conditionally useEffect on the server (no-op) and\n// useLayoutEffect in the browser. We need useLayoutEffect to ensure the store\n// subscription callback always has the selector from the latest render commit\n// available, otherwise a store update may happen between render and the effect,\n// which may cause missed updates; we also must ensure the store subscription\n// is created synchronously, otherwise a store update may occur before the\n// subscription is created and an inconsistent state may be observed\n\n// Matches logic in React's `shared/ExecutionEnvironment` file\nexport const canUseDOM = !!(\n typeof window !== 'undefined' &&\n typeof window.document !== 'undefined' &&\n typeof window.document.createElement !== 'undefined'\n)\n\n// Under React Native, we know that we always want to use useLayoutEffect\n\n/**\n * Checks if the code is running in a React Native environment.\n *\n * @see {@link https://github.com/facebook/react-native/issues/1331 Reference}\n */\nexport const isReactNative =\n typeof navigator !== 'undefined' && navigator.product === 'ReactNative'\n\nexport const useIsomorphicLayoutEffect =\n canUseDOM || isReactNative ? React.useLayoutEffect : React.useEffect\n","function is(x: unknown, y: unknown) {\r\n if (x === y) {\r\n return x !== 0 || y !== 0 || 1 / x === 1 / y\r\n } else {\r\n return x !== x && y !== y\r\n }\r\n}\r\n\r\nexport default function shallowEqual(objA: any, objB: any) {\r\n if (is(objA, objB)) return true\r\n\r\n if (\r\n typeof objA !== 'object' ||\r\n objA === null ||\r\n typeof objB !== 'object' ||\r\n objB === null\r\n ) {\r\n return false\r\n }\r\n\r\n const keysA = Object.keys(objA)\r\n const keysB = Object.keys(objB)\r\n\r\n if (keysA.length !== keysB.length) return false\r\n\r\n for (let i = 0; i < keysA.length; i++) {\r\n if (\r\n !Object.prototype.hasOwnProperty.call(objB, keysA[i]) ||\r\n !is(objA[keysA[i]], objB[keysA[i]])\r\n ) {\r\n return false\r\n }\r\n }\r\n\r\n return true\r\n}\r\n","// Copied directly from:\n// https://github.com/mridgway/hoist-non-react-statics/blob/main/src/index.js\n// https://unpkg.com/browse/@types/hoist-non-react-statics@3.3.1/index.d.ts\n\n/**\n * Copyright 2015, Yahoo! Inc.\n * Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms.\n */\nimport type * as React from 'react'\nimport { ForwardRef, Memo, isMemo } from '../utils/react-is'\n\nconst REACT_STATICS = {\n childContextTypes: true,\n contextType: true,\n contextTypes: true,\n defaultProps: true,\n displayName: true,\n getDefaultProps: true,\n getDerivedStateFromError: true,\n getDerivedStateFromProps: true,\n mixins: true,\n propTypes: true,\n type: true,\n} as const\n\nconst KNOWN_STATICS = {\n name: true,\n length: true,\n prototype: true,\n caller: true,\n callee: true,\n arguments: true,\n arity: true,\n} as const\n\nconst FORWARD_REF_STATICS = {\n $$typeof: true,\n render: true,\n defaultProps: true,\n displayName: true,\n propTypes: true,\n} as const\n\nconst MEMO_STATICS = {\n $$typeof: true,\n compare: true,\n defaultProps: true,\n displayName: true,\n propTypes: true,\n type: true,\n} as const\n\nconst TYPE_STATICS = {\n [ForwardRef]: FORWARD_REF_STATICS,\n [Memo]: MEMO_STATICS,\n} as const\n\nfunction getStatics(component: any) {\n // React v16.11 and below\n if (isMemo(component)) {\n return MEMO_STATICS\n }\n\n // React v16.12 and above\n return TYPE_STATICS[component['$$typeof']] || REACT_STATICS\n}\n\nexport type NonReactStatics<\n S extends React.ComponentType,\n C extends {\n [key: string]: true\n } = {},\n> = {\n [key in Exclude<\n keyof S,\n S extends React.MemoExoticComponent\n ? keyof typeof MEMO_STATICS | keyof C\n : S extends React.ForwardRefExoticComponent\n ? keyof typeof FORWARD_REF_STATICS | keyof C\n : keyof typeof REACT_STATICS | keyof typeof KNOWN_STATICS | keyof C\n >]: S[key]\n}\n\nconst defineProperty = Object.defineProperty\nconst getOwnPropertyNames = Object.getOwnPropertyNames\nconst getOwnPropertySymbols = Object.getOwnPropertySymbols\nconst getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor\nconst getPrototypeOf = Object.getPrototypeOf\nconst objectPrototype = Object.prototype\n\nexport default function hoistNonReactStatics<\n T extends React.ComponentType,\n S extends React.ComponentType,\n C extends {\n [key: string]: true\n } = {},\n>(targetComponent: T, sourceComponent: S): T & NonReactStatics {\n if (typeof sourceComponent !== 'string') {\n // don't hoist over string (html) components\n\n if (objectPrototype) {\n const inheritedComponent = getPrototypeOf(sourceComponent)\n if (inheritedComponent && inheritedComponent !== objectPrototype) {\n hoistNonReactStatics(targetComponent, inheritedComponent)\n }\n }\n\n let keys: (string | symbol)[] = getOwnPropertyNames(sourceComponent)\n\n if (getOwnPropertySymbols) {\n keys = keys.concat(getOwnPropertySymbols(sourceComponent))\n }\n\n const targetStatics = getStatics(targetComponent)\n const sourceStatics = getStatics(sourceComponent)\n\n for (let i = 0; i < keys.length; ++i) {\n const key = keys[i]\n if (\n !KNOWN_STATICS[key as keyof typeof KNOWN_STATICS] &&\n !(sourceStatics && sourceStatics[key as keyof typeof sourceStatics]) &&\n !(targetStatics && targetStatics[key as keyof typeof targetStatics])\n ) {\n const descriptor = getOwnPropertyDescriptor(sourceComponent, key)\n try {\n // Avoid failures from read-only properties\n defineProperty(targetComponent, key, descriptor!)\n } catch (e) {\n // ignore\n }\n }\n }\n }\n\n return targetComponent as any\n}\n","/* eslint-disable valid-jsdoc, @typescript-eslint/no-unused-vars */\nimport type { ComponentType } from 'react'\nimport { React } from '../utils/react'\nimport { isValidElementType, isContextConsumer } from '../utils/react-is'\n\nimport type { Store } from 'redux'\n\nimport type {\n ConnectedComponent,\n InferableComponentEnhancer,\n InferableComponentEnhancerWithProps,\n ResolveThunks,\n DispatchProp,\n ConnectPropsMaybeWithoutContext,\n} from '../types'\n\nimport type {\n MapStateToPropsParam,\n MapDispatchToPropsParam,\n MergeProps,\n MapDispatchToPropsNonObject,\n SelectorFactoryOptions,\n} from '../connect/selectorFactory'\nimport defaultSelectorFactory from '../connect/selectorFactory'\nimport { mapDispatchToPropsFactory } from '../connect/mapDispatchToProps'\nimport { mapStateToPropsFactory } from '../connect/mapStateToProps'\nimport { mergePropsFactory } from '../connect/mergeProps'\n\nimport type { Subscription } from '../utils/Subscription'\nimport { createSubscription } from '../utils/Subscription'\nimport { useIsomorphicLayoutEffect } from '../utils/useIsomorphicLayoutEffect'\nimport shallowEqual from '../utils/shallowEqual'\nimport hoistStatics from '../utils/hoistStatics'\nimport warning from '../utils/warning'\n\nimport type {\n ReactReduxContextValue,\n ReactReduxContextInstance,\n} from './Context'\nimport { ReactReduxContext } from './Context'\n\nimport type { uSES } from '../utils/useSyncExternalStore'\nimport { notInitialized } from '../utils/useSyncExternalStore'\n\nlet useSyncExternalStore = notInitialized as uSES\nexport const initializeConnect = (fn: uSES) => {\n useSyncExternalStore = fn\n}\n\n// Define some constant arrays just to avoid re-creating these\nconst EMPTY_ARRAY: [unknown, number] = [null, 0]\nconst NO_SUBSCRIPTION_ARRAY = [null, null]\n\n// Attempts to stringify whatever not-really-a-component value we were given\n// for logging in an error message\nconst stringifyComponent = (Comp: unknown) => {\n try {\n return JSON.stringify(Comp)\n } catch (err) {\n return String(Comp)\n }\n}\n\ntype EffectFunc = (...args: any[]) => void | ReturnType\n\n// This is \"just\" a `useLayoutEffect`, but with two modifications:\n// - we need to fall back to `useEffect` in SSR to avoid annoying warnings\n// - we extract this to a separate function to avoid closing over values\n// and causing memory leaks\nfunction useIsomorphicLayoutEffectWithArgs(\n effectFunc: EffectFunc,\n effectArgs: any[],\n dependencies?: React.DependencyList,\n) {\n useIsomorphicLayoutEffect(() => effectFunc(...effectArgs), dependencies)\n}\n\n// Effect callback, extracted: assign the latest props values to refs for later usage\nfunction captureWrapperProps(\n lastWrapperProps: React.MutableRefObject,\n lastChildProps: React.MutableRefObject,\n renderIsScheduled: React.MutableRefObject,\n wrapperProps: unknown,\n // actualChildProps: unknown,\n childPropsFromStoreUpdate: React.MutableRefObject,\n notifyNestedSubs: () => void,\n) {\n // We want to capture the wrapper props and child props we used for later comparisons\n lastWrapperProps.current = wrapperProps\n renderIsScheduled.current = false\n\n // If the render was from a store update, clear out that reference and cascade the subscriber update\n if (childPropsFromStoreUpdate.current) {\n childPropsFromStoreUpdate.current = null\n notifyNestedSubs()\n }\n}\n\n// Effect callback, extracted: subscribe to the Redux store or nearest connected ancestor,\n// check for updates after dispatched actions, and trigger re-renders.\nfunction subscribeUpdates(\n shouldHandleStateChanges: boolean,\n store: Store,\n subscription: Subscription,\n childPropsSelector: (state: unknown, props: unknown) => unknown,\n lastWrapperProps: React.MutableRefObject,\n lastChildProps: React.MutableRefObject,\n renderIsScheduled: React.MutableRefObject,\n isMounted: React.MutableRefObject,\n childPropsFromStoreUpdate: React.MutableRefObject,\n notifyNestedSubs: () => void,\n // forceComponentUpdateDispatch: React.Dispatch,\n additionalSubscribeListener: () => void,\n) {\n // If we're not subscribed to the store, nothing to do here\n if (!shouldHandleStateChanges) return () => {}\n\n // Capture values for checking if and when this component unmounts\n let didUnsubscribe = false\n let lastThrownError: Error | null = null\n\n // We'll run this callback every time a store subscription update propagates to this component\n const checkForUpdates = () => {\n if (didUnsubscribe || !isMounted.current) {\n // Don't run stale listeners.\n // Redux doesn't guarantee unsubscriptions happen until next dispatch.\n return\n }\n\n // TODO We're currently calling getState ourselves here, rather than letting `uSES` do it\n const latestStoreState = store.getState()\n\n let newChildProps, error\n try {\n // Actually run the selector with the most recent store state and wrapper props\n // to determine what the child props should be\n newChildProps = childPropsSelector(\n latestStoreState,\n lastWrapperProps.current,\n )\n } catch (e) {\n error = e\n lastThrownError = e as Error | null\n }\n\n if (!error) {\n lastThrownError = null\n }\n\n // If the child props haven't changed, nothing to do here - cascade the subscription update\n if (newChildProps === lastChildProps.current) {\n if (!renderIsScheduled.current) {\n notifyNestedSubs()\n }\n } else {\n // Save references to the new child props. Note that we track the \"child props from store update\"\n // as a ref instead of a useState/useReducer because we need a way to determine if that value has\n // been processed. If this went into useState/useReducer, we couldn't clear out the value without\n // forcing another re-render, which we don't want.\n lastChildProps.current = newChildProps\n childPropsFromStoreUpdate.current = newChildProps\n renderIsScheduled.current = true\n\n // TODO This is hacky and not how `uSES` is meant to be used\n // Trigger the React `useSyncExternalStore` subscriber\n additionalSubscribeListener()\n }\n }\n\n // Actually subscribe to the nearest connected ancestor (or store)\n subscription.onStateChange = checkForUpdates\n subscription.trySubscribe()\n\n // Pull data from the store after first render in case the store has\n // changed since we began.\n checkForUpdates()\n\n const unsubscribeWrapper = () => {\n didUnsubscribe = true\n subscription.tryUnsubscribe()\n subscription.onStateChange = null\n\n if (lastThrownError) {\n // It's possible that we caught an error due to a bad mapState function, but the\n // parent re-rendered without this component and we're about to unmount.\n // This shouldn't happen as long as we do top-down subscriptions correctly, but\n // if we ever do those wrong, this throw will surface the error in our tests.\n // In that case, throw the error from here so it doesn't get lost.\n throw lastThrownError\n }\n }\n\n return unsubscribeWrapper\n}\n\n// Reducer initial state creation for our update reducer\nconst initStateUpdates = () => EMPTY_ARRAY\n\nexport interface ConnectProps {\n /** A custom Context instance that the component can use to access the store from an alternate Provider using that same Context instance */\n context?: ReactReduxContextInstance\n /** A Redux store instance to be used for subscriptions instead of the store from a Provider */\n store?: Store\n}\n\ninterface InternalConnectProps extends ConnectProps {\n reactReduxForwardedRef?: React.ForwardedRef\n}\n\nfunction strictEqual(a: unknown, b: unknown) {\n return a === b\n}\n\n/**\n * Infers the type of props that a connector will inject into a component.\n */\nexport type ConnectedProps =\n TConnector extends InferableComponentEnhancerWithProps<\n infer TInjectedProps,\n any\n >\n ? unknown extends TInjectedProps\n ? TConnector extends InferableComponentEnhancer\n ? TInjectedProps\n : never\n : TInjectedProps\n : never\n\nexport interface ConnectOptions<\n State = unknown,\n TStateProps = {},\n TOwnProps = {},\n TMergedProps = {},\n> {\n forwardRef?: boolean\n context?: typeof ReactReduxContext\n areStatesEqual?: (\n nextState: State,\n prevState: State,\n nextOwnProps: TOwnProps,\n prevOwnProps: TOwnProps,\n ) => boolean\n\n areOwnPropsEqual?: (\n nextOwnProps: TOwnProps,\n prevOwnProps: TOwnProps,\n ) => boolean\n\n areStatePropsEqual?: (\n nextStateProps: TStateProps,\n prevStateProps: TStateProps,\n ) => boolean\n areMergedPropsEqual?: (\n nextMergedProps: TMergedProps,\n prevMergedProps: TMergedProps,\n ) => boolean\n}\n\n/**\n * Connects a React component to a Redux store.\n *\n * - Without arguments, just wraps the component, without changing the behavior / props\n *\n * - If 2 params are passed (3rd param, mergeProps, is skipped), default behavior\n * is to override ownProps (as stated in the docs), so what remains is everything that's\n * not a state or dispatch prop\n *\n * - When 3rd param is passed, we don't know if ownProps propagate and whether they\n * should be valid component props, because it depends on mergeProps implementation.\n * As such, it is the user's responsibility to extend ownProps interface from state or\n * dispatch props or both when applicable\n *\n * @param mapStateToProps\n * @param mapDispatchToProps\n * @param mergeProps\n * @param options\n */\nexport interface Connect {\n // tslint:disable:no-unnecessary-generics\n (): InferableComponentEnhancer\n\n /** mapState only */\n (\n mapStateToProps: MapStateToPropsParam,\n ): InferableComponentEnhancerWithProps\n\n /** mapDispatch only (as a function) */\n (\n mapStateToProps: null | undefined,\n mapDispatchToProps: MapDispatchToPropsNonObject,\n ): InferableComponentEnhancerWithProps\n\n /** mapDispatch only (as an object) */\n (\n mapStateToProps: null | undefined,\n mapDispatchToProps: MapDispatchToPropsParam,\n ): InferableComponentEnhancerWithProps<\n ResolveThunks,\n TOwnProps\n >\n\n /** mapState and mapDispatch (as a function)*/\n (\n mapStateToProps: MapStateToPropsParam,\n mapDispatchToProps: MapDispatchToPropsNonObject,\n ): InferableComponentEnhancerWithProps<\n TStateProps & TDispatchProps,\n TOwnProps\n >\n\n /** mapState and mapDispatch (nullish) */\n (\n mapStateToProps: MapStateToPropsParam,\n mapDispatchToProps: null | undefined,\n ): InferableComponentEnhancerWithProps\n\n /** mapState and mapDispatch (as an object) */\n (\n mapStateToProps: MapStateToPropsParam,\n mapDispatchToProps: MapDispatchToPropsParam,\n ): InferableComponentEnhancerWithProps<\n TStateProps & ResolveThunks,\n TOwnProps\n >\n\n /** mergeProps only */\n (\n mapStateToProps: null | undefined,\n mapDispatchToProps: null | undefined,\n mergeProps: MergeProps,\n ): InferableComponentEnhancerWithProps\n\n /** mapState and mergeProps */\n <\n TStateProps = {},\n no_dispatch = {},\n TOwnProps = {},\n TMergedProps = {},\n State = DefaultState,\n >(\n mapStateToProps: MapStateToPropsParam,\n mapDispatchToProps: null | undefined,\n mergeProps: MergeProps,\n ): InferableComponentEnhancerWithProps\n\n /** mapDispatch (as a object) and mergeProps */\n (\n mapStateToProps: null | undefined,\n mapDispatchToProps: MapDispatchToPropsParam,\n mergeProps: MergeProps,\n ): InferableComponentEnhancerWithProps\n\n /** mapState and options */\n (\n mapStateToProps: MapStateToPropsParam,\n mapDispatchToProps: null | undefined,\n mergeProps: null | undefined,\n options: ConnectOptions,\n ): InferableComponentEnhancerWithProps\n\n /** mapDispatch (as a function) and options */\n (\n mapStateToProps: null | undefined,\n mapDispatchToProps: MapDispatchToPropsNonObject,\n mergeProps: null | undefined,\n options: ConnectOptions<{}, TStateProps, TOwnProps>,\n ): InferableComponentEnhancerWithProps\n\n /** mapDispatch (as an object) and options*/\n (\n mapStateToProps: null | undefined,\n mapDispatchToProps: MapDispatchToPropsParam,\n mergeProps: null | undefined,\n options: ConnectOptions<{}, TStateProps, TOwnProps>,\n ): InferableComponentEnhancerWithProps<\n ResolveThunks,\n TOwnProps\n >\n\n /** mapState, mapDispatch (as a function), and options */\n (\n mapStateToProps: MapStateToPropsParam,\n mapDispatchToProps: MapDispatchToPropsNonObject,\n mergeProps: null | undefined,\n options: ConnectOptions,\n ): InferableComponentEnhancerWithProps<\n TStateProps & TDispatchProps,\n TOwnProps\n >\n\n /** mapState, mapDispatch (as an object), and options */\n (\n mapStateToProps: MapStateToPropsParam,\n mapDispatchToProps: MapDispatchToPropsParam,\n mergeProps: null | undefined,\n options: ConnectOptions,\n ): InferableComponentEnhancerWithProps<\n TStateProps & ResolveThunks,\n TOwnProps\n >\n\n /** mapState, mapDispatch, mergeProps, and options */\n <\n TStateProps = {},\n TDispatchProps = {},\n TOwnProps = {},\n TMergedProps = {},\n State = DefaultState,\n >(\n mapStateToProps: MapStateToPropsParam,\n mapDispatchToProps: MapDispatchToPropsParam,\n mergeProps: MergeProps<\n TStateProps,\n TDispatchProps,\n TOwnProps,\n TMergedProps\n >,\n options?: ConnectOptions,\n ): InferableComponentEnhancerWithProps\n // tslint:enable:no-unnecessary-generics\n}\n\nlet hasWarnedAboutDeprecatedPureOption = false\n\n/**\n * Connects a React component to a Redux store.\n *\n * - Without arguments, just wraps the component, without changing the behavior / props\n *\n * - If 2 params are passed (3rd param, mergeProps, is skipped), default behavior\n * is to override ownProps (as stated in the docs), so what remains is everything that's\n * not a state or dispatch prop\n *\n * - When 3rd param is passed, we don't know if ownProps propagate and whether they\n * should be valid component props, because it depends on mergeProps implementation.\n * As such, it is the user's responsibility to extend ownProps interface from state or\n * dispatch props or both when applicable\n *\n * @param mapStateToProps A function that extracts values from state\n * @param mapDispatchToProps Setup for dispatching actions\n * @param mergeProps Optional callback to merge state and dispatch props together\n * @param options Options for configuring the connection\n *\n */\nfunction connect<\n TStateProps = {},\n TDispatchProps = {},\n TOwnProps = {},\n TMergedProps = {},\n State = unknown,\n>(\n mapStateToProps?: MapStateToPropsParam,\n mapDispatchToProps?: MapDispatchToPropsParam,\n mergeProps?: MergeProps,\n {\n // The `pure` option has been removed, so TS doesn't like us destructuring this to check its existence.\n // @ts-ignore\n pure,\n areStatesEqual = strictEqual,\n areOwnPropsEqual = shallowEqual,\n areStatePropsEqual = shallowEqual,\n areMergedPropsEqual = shallowEqual,\n\n // use React's forwardRef to expose a ref of the wrapped component\n forwardRef = false,\n\n // the context consumer to use\n context = ReactReduxContext,\n }: ConnectOptions = {},\n): unknown {\n if (process.env.NODE_ENV !== 'production') {\n if (pure !== undefined && !hasWarnedAboutDeprecatedPureOption) {\n hasWarnedAboutDeprecatedPureOption = true\n warning(\n 'The `pure` option has been removed. `connect` is now always a \"pure/memoized\" component',\n )\n }\n }\n\n const Context = context\n\n const initMapStateToProps = mapStateToPropsFactory(mapStateToProps)\n const initMapDispatchToProps = mapDispatchToPropsFactory(mapDispatchToProps)\n const initMergeProps = mergePropsFactory(mergeProps)\n\n const shouldHandleStateChanges = Boolean(mapStateToProps)\n\n const wrapWithConnect = (\n WrappedComponent: ComponentType,\n ) => {\n type WrappedComponentProps = TProps &\n ConnectPropsMaybeWithoutContext\n\n if (process.env.NODE_ENV !== 'production') {\n const isValid = /*#__PURE__*/ isValidElementType(WrappedComponent)\n if (!isValid)\n throw new Error(\n `You must pass a component to the function returned by connect. Instead received ${stringifyComponent(\n WrappedComponent,\n )}`,\n )\n }\n\n const wrappedComponentName =\n WrappedComponent.displayName || WrappedComponent.name || 'Component'\n\n const displayName = `Connect(${wrappedComponentName})`\n\n const selectorFactoryOptions: SelectorFactoryOptions<\n any,\n any,\n any,\n any,\n State\n > = {\n shouldHandleStateChanges,\n displayName,\n wrappedComponentName,\n WrappedComponent,\n // @ts-ignore\n initMapStateToProps,\n // @ts-ignore\n initMapDispatchToProps,\n initMergeProps,\n areStatesEqual,\n areStatePropsEqual,\n areOwnPropsEqual,\n areMergedPropsEqual,\n }\n\n function ConnectFunction(\n props: InternalConnectProps & TOwnProps,\n ) {\n const [propsContext, reactReduxForwardedRef, wrapperProps] =\n React.useMemo(() => {\n // Distinguish between actual \"data\" props that were passed to the wrapper component,\n // and values needed to control behavior (forwarded refs, alternate context instances).\n // To maintain the wrapperProps object reference, memoize this destructuring.\n const { reactReduxForwardedRef, ...wrapperProps } = props\n return [props.context, reactReduxForwardedRef, wrapperProps]\n }, [props])\n\n const ContextToUse: ReactReduxContextInstance = React.useMemo(() => {\n // Users may optionally pass in a custom context instance to use instead of our ReactReduxContext.\n // Memoize the check that determines which context instance we should use.\n let ResultContext = Context\n if (propsContext?.Consumer) {\n if (process.env.NODE_ENV !== 'production') {\n const isValid = /*#__PURE__*/ isContextConsumer(\n // @ts-ignore\n ,\n )\n if (!isValid) {\n throw new Error(\n 'You must pass a valid React context consumer as `props.context`',\n )\n }\n ResultContext = propsContext\n }\n }\n return ResultContext\n }, [propsContext, Context])\n\n // Retrieve the store and ancestor subscription via context, if available\n const contextValue = React.useContext(ContextToUse)\n\n // The store _must_ exist as either a prop or in context.\n // We'll check to see if it _looks_ like a Redux store first.\n // This allows us to pass through a `store` prop that is just a plain value.\n const didStoreComeFromProps =\n Boolean(props.store) &&\n Boolean(props.store!.getState) &&\n Boolean(props.store!.dispatch)\n const didStoreComeFromContext =\n Boolean(contextValue) && Boolean(contextValue!.store)\n\n if (\n process.env.NODE_ENV !== 'production' &&\n !didStoreComeFromProps &&\n !didStoreComeFromContext\n ) {\n throw new Error(\n `Could not find \"store\" in the context of ` +\n `\"${displayName}\". Either wrap the root component in a , ` +\n `or pass a custom React context provider to and the corresponding ` +\n `React context consumer to ${displayName} in connect options.`,\n )\n }\n\n // Based on the previous check, one of these must be true\n const store: Store = didStoreComeFromProps\n ? props.store!\n : contextValue!.store\n\n const getServerState = didStoreComeFromContext\n ? contextValue!.getServerState\n : store.getState\n\n const childPropsSelector = React.useMemo(() => {\n // The child props selector needs the store reference as an input.\n // Re-create this selector whenever the store changes.\n return defaultSelectorFactory(store.dispatch, selectorFactoryOptions)\n }, [store])\n\n const [subscription, notifyNestedSubs] = React.useMemo(() => {\n if (!shouldHandleStateChanges) return NO_SUBSCRIPTION_ARRAY\n\n // This Subscription's source should match where store came from: props vs. context. A component\n // connected to the store via props shouldn't use subscription from context, or vice versa.\n const subscription = createSubscription(\n store,\n didStoreComeFromProps ? undefined : contextValue!.subscription,\n )\n\n // `notifyNestedSubs` is duplicated to handle the case where the component is unmounted in\n // the middle of the notification loop, where `subscription` will then be null. This can\n // probably be avoided if Subscription's listeners logic is changed to not call listeners\n // that have been unsubscribed in the middle of the notification loop.\n const notifyNestedSubs =\n subscription.notifyNestedSubs.bind(subscription)\n\n return [subscription, notifyNestedSubs]\n }, [store, didStoreComeFromProps, contextValue])\n\n // Determine what {store, subscription} value should be put into nested context, if necessary,\n // and memoize that value to avoid unnecessary context updates.\n const overriddenContextValue = React.useMemo(() => {\n if (didStoreComeFromProps) {\n // This component is directly subscribed to a store from props.\n // We don't want descendants reading from this store - pass down whatever\n // the existing context value is from the nearest connected ancestor.\n return contextValue!\n }\n\n // Otherwise, put this component's subscription instance into context, so that\n // connected descendants won't update until after this component is done\n return {\n ...contextValue,\n subscription,\n } as ReactReduxContextValue\n }, [didStoreComeFromProps, contextValue, subscription])\n\n // Set up refs to coordinate values between the subscription effect and the render logic\n const lastChildProps = React.useRef(undefined)\n const lastWrapperProps = React.useRef(wrapperProps)\n const childPropsFromStoreUpdate = React.useRef(undefined)\n const renderIsScheduled = React.useRef(false)\n const isMounted = React.useRef(false)\n\n // TODO: Change this to `React.useRef(undefined)` after upgrading to React 19.\n /**\n * @todo Change this to `React.useRef(undefined)` after upgrading to React 19.\n */\n const latestSubscriptionCallbackError = React.useRef(\n undefined,\n )\n\n useIsomorphicLayoutEffect(() => {\n isMounted.current = true\n return () => {\n isMounted.current = false\n }\n }, [])\n\n const actualChildPropsSelector = React.useMemo(() => {\n const selector = () => {\n // Tricky logic here:\n // - This render may have been triggered by a Redux store update that produced new child props\n // - However, we may have gotten new wrapper props after that\n // If we have new child props, and the same wrapper props, we know we should use the new child props as-is.\n // But, if we have new wrapper props, those might change the child props, so we have to recalculate things.\n // So, we'll use the child props from store update only if the wrapper props are the same as last time.\n if (\n childPropsFromStoreUpdate.current &&\n wrapperProps === lastWrapperProps.current\n ) {\n return childPropsFromStoreUpdate.current\n }\n\n // TODO We're reading the store directly in render() here. Bad idea?\n // This will likely cause Bad Things (TM) to happen in Concurrent Mode.\n // Note that we do this because on renders _not_ caused by store updates, we need the latest store state\n // to determine what the child props should be.\n return childPropsSelector(store.getState(), wrapperProps)\n }\n return selector\n }, [store, wrapperProps])\n\n // We need this to execute synchronously every time we re-render. However, React warns\n // about useLayoutEffect in SSR, so we try to detect environment and fall back to\n // just useEffect instead to avoid the warning, since neither will run anyway.\n\n const subscribeForReact = React.useMemo(() => {\n const subscribe = (reactListener: () => void) => {\n if (!subscription) {\n return () => {}\n }\n\n return subscribeUpdates(\n shouldHandleStateChanges,\n store,\n subscription,\n // @ts-ignore\n childPropsSelector,\n lastWrapperProps,\n lastChildProps,\n renderIsScheduled,\n isMounted,\n childPropsFromStoreUpdate,\n notifyNestedSubs,\n reactListener,\n )\n }\n\n return subscribe\n }, [subscription])\n\n useIsomorphicLayoutEffectWithArgs(captureWrapperProps, [\n lastWrapperProps,\n lastChildProps,\n renderIsScheduled,\n wrapperProps,\n childPropsFromStoreUpdate,\n notifyNestedSubs,\n ])\n\n let actualChildProps: Record\n\n try {\n actualChildProps = useSyncExternalStore(\n // TODO We're passing through a big wrapper that does a bunch of extra side effects besides subscribing\n subscribeForReact,\n // TODO This is incredibly hacky. We've already processed the store update and calculated new child props,\n // TODO and we're just passing that through so it triggers a re-render for us rather than relying on `uSES`.\n actualChildPropsSelector,\n getServerState\n ? () => childPropsSelector(getServerState(), wrapperProps)\n : actualChildPropsSelector,\n )\n } catch (err) {\n if (latestSubscriptionCallbackError.current) {\n // eslint-disable-next-line no-extra-semi\n ;(err as Error).message +=\n `\\nThe error may be correlated with this previous error:\\n${latestSubscriptionCallbackError.current.stack}\\n\\n`\n }\n\n throw err\n }\n\n useIsomorphicLayoutEffect(() => {\n latestSubscriptionCallbackError.current = undefined\n childPropsFromStoreUpdate.current = undefined\n lastChildProps.current = actualChildProps\n })\n\n // Now that all that's done, we can finally try to actually render the child component.\n // We memoize the elements for the rendered child component as an optimization.\n const renderedWrappedComponent = React.useMemo(() => {\n return (\n // @ts-ignore\n \n )\n }, [reactReduxForwardedRef, WrappedComponent, actualChildProps])\n\n // If React sees the exact same element reference as last time, it bails out of re-rendering\n // that child, same as if it was wrapped in React.memo() or returned false from shouldComponentUpdate.\n const renderedChild = React.useMemo(() => {\n if (shouldHandleStateChanges) {\n // If this component is subscribed to store updates, we need to pass its own\n // subscription instance down to our descendants. That means rendering the same\n // Context instance, and putting a different value into the context.\n return (\n \n {renderedWrappedComponent}\n \n )\n }\n\n return renderedWrappedComponent\n }, [ContextToUse, renderedWrappedComponent, overriddenContextValue])\n\n return renderedChild\n }\n\n const _Connect = React.memo(ConnectFunction)\n\n type ConnectedWrapperComponent = typeof _Connect & {\n WrappedComponent: typeof WrappedComponent\n }\n\n // Add a hacky cast to get the right output type\n const Connect = _Connect as unknown as ConnectedComponent<\n typeof WrappedComponent,\n WrappedComponentProps\n >\n Connect.WrappedComponent = WrappedComponent\n Connect.displayName = ConnectFunction.displayName = displayName\n\n if (forwardRef) {\n const _forwarded = React.forwardRef(\n function forwardConnectRef(props, ref) {\n // @ts-ignore\n return \n },\n )\n\n const forwarded = _forwarded as ConnectedWrapperComponent\n forwarded.displayName = displayName\n forwarded.WrappedComponent = WrappedComponent\n return /*#__PURE__*/ hoistStatics(forwarded, WrappedComponent)\n }\n\n return /*#__PURE__*/ hoistStatics(Connect, WrappedComponent)\n }\n\n return wrapWithConnect\n}\n\nexport default connect as Connect\n","import { wrapMapToPropsConstant, wrapMapToPropsFunc } from './wrapMapToProps'\nimport { createInvalidArgFactory } from './invalidArgFactory'\nimport type { MapStateToPropsParam } from './selectorFactory'\n\nexport function mapStateToPropsFactory(\n mapStateToProps: MapStateToPropsParam,\n) {\n return !mapStateToProps\n ? wrapMapToPropsConstant(() => ({}))\n : typeof mapStateToProps === 'function'\n ? // @ts-ignore\n wrapMapToPropsFunc(mapStateToProps, 'mapStateToProps')\n : createInvalidArgFactory(mapStateToProps, 'mapStateToProps')\n}\n","import type { Action, Dispatch } from 'redux'\nimport bindActionCreators from '../utils/bindActionCreators'\nimport { wrapMapToPropsConstant, wrapMapToPropsFunc } from './wrapMapToProps'\nimport { createInvalidArgFactory } from './invalidArgFactory'\nimport type { MapDispatchToPropsParam } from './selectorFactory'\n\nexport function mapDispatchToPropsFactory(\n mapDispatchToProps:\n | MapDispatchToPropsParam\n | undefined,\n) {\n return mapDispatchToProps && typeof mapDispatchToProps === 'object'\n ? wrapMapToPropsConstant((dispatch: Dispatch>) =>\n // @ts-ignore\n bindActionCreators(mapDispatchToProps, dispatch),\n )\n : !mapDispatchToProps\n ? wrapMapToPropsConstant((dispatch: Dispatch>) => ({\n dispatch,\n }))\n : typeof mapDispatchToProps === 'function'\n ? // @ts-ignore\n wrapMapToPropsFunc(mapDispatchToProps, 'mapDispatchToProps')\n : createInvalidArgFactory(mapDispatchToProps, 'mapDispatchToProps')\n}\n","import type { ActionCreatorsMapObject, Dispatch } from 'redux'\n\nexport default function bindActionCreators(\n actionCreators: ActionCreatorsMapObject,\n dispatch: Dispatch,\n): ActionCreatorsMapObject {\n const boundActionCreators: ActionCreatorsMapObject = {}\n\n for (const key in actionCreators) {\n const actionCreator = actionCreators[key]\n if (typeof actionCreator === 'function') {\n boundActionCreators[key] = (...args) => dispatch(actionCreator(...args))\n }\n }\n return boundActionCreators\n}\n","import type { Context, ReactNode } from 'react'\nimport { React } from '../utils/react'\nimport type { Action, Store, UnknownAction } from 'redux'\nimport type { DevModeCheckFrequency } from '../hooks/useSelector'\nimport { createSubscription } from '../utils/Subscription'\nimport { useIsomorphicLayoutEffect } from '../utils/useIsomorphicLayoutEffect'\nimport type { ReactReduxContextValue } from './Context'\nimport { ReactReduxContext } from './Context'\n\nexport interface ProviderProps<\n A extends Action = UnknownAction,\n S = unknown,\n> {\n /**\n * The single Redux store in your application.\n */\n store: Store\n\n /**\n * An optional server state snapshot. Will be used during initial hydration render if available, to ensure that the UI output is consistent with the HTML generated on the server.\n */\n serverState?: S\n\n /**\n * Optional context to be used internally in react-redux. Use React.createContext() to create a context to be used.\n * If this is used, you'll need to customize `connect` by supplying the same context provided to the Provider.\n * Set the initial value to null, and the hooks will error\n * if this is not overwritten by Provider.\n */\n context?: Context | null>\n\n /**\n * Determines the frequency of stability checks for all selectors.\n * This setting overrides the global configuration for\n * the `useSelector` stability check, allowing you to specify how often\n * these checks should occur in development mode.\n *\n * @since 8.1.0\n */\n stabilityCheck?: DevModeCheckFrequency\n\n /**\n * Determines the frequency of identity function checks for all selectors.\n * This setting overrides the global configuration for\n * the `useSelector` identity function check, allowing you to specify how often\n * these checks should occur in development mode.\n *\n * **Note**: Previously referred to as `noopCheck`.\n *\n * @since 9.0.0\n */\n identityFunctionCheck?: DevModeCheckFrequency\n\n children: ReactNode\n}\n\nfunction Provider = UnknownAction, S = unknown>({\n store,\n context,\n children,\n serverState,\n stabilityCheck = 'once',\n identityFunctionCheck = 'once',\n}: ProviderProps) {\n const contextValue = React.useMemo(() => {\n const subscription = createSubscription(store)\n return {\n store,\n subscription,\n getServerState: serverState ? () => serverState : undefined,\n stabilityCheck,\n identityFunctionCheck,\n }\n }, [store, serverState, stabilityCheck, identityFunctionCheck])\n\n const previousState = React.useMemo(() => store.getState(), [store])\n\n useIsomorphicLayoutEffect(() => {\n const { subscription } = contextValue\n subscription.onStateChange = subscription.notifyNestedSubs\n subscription.trySubscribe()\n\n if (previousState !== store.getState()) {\n subscription.notifyNestedSubs()\n }\n return () => {\n subscription.tryUnsubscribe()\n subscription.onStateChange = undefined\n }\n }, [contextValue, previousState])\n\n const Context = context || ReactReduxContext\n\n // @ts-ignore 'AnyAction' is assignable to the constraint of type 'A', but 'A' could be instantiated with a different subtype\n return {children}\n}\n\nexport default Provider\n","import type { Context } from 'react'\nimport type { Action, Store } from 'redux'\nimport type { ReactReduxContextValue } from '../components/Context'\nimport { ReactReduxContext } from '../components/Context'\nimport {\n createReduxContextHook,\n useReduxContext as useDefaultReduxContext,\n} from './useReduxContext'\n\n/**\n * Represents a type that extracts the action type from a given Redux store.\n *\n * @template StoreType - The specific type of the Redux store.\n *\n * @since 9.1.0\n * @internal\n */\nexport type ExtractStoreActionType =\n StoreType extends Store ? ActionType : never\n\n/**\n * Represents a custom hook that provides access to the Redux store.\n *\n * @template StoreType - The specific type of the Redux store that gets returned.\n *\n * @since 9.1.0\n * @public\n */\nexport interface UseStore {\n /**\n * Returns the Redux store instance.\n *\n * @returns The Redux store instance.\n */\n (): StoreType\n\n /**\n * Returns the Redux store instance with specific state and action types.\n *\n * @returns The Redux store with the specified state and action types.\n *\n * @template StateType - The specific type of the state used in the store.\n * @template ActionType - The specific type of the actions used in the store.\n */\n <\n StateType extends ReturnType = ReturnType<\n StoreType['getState']\n >,\n ActionType extends Action = ExtractStoreActionType,\n >(): Store\n\n /**\n * Creates a \"pre-typed\" version of {@linkcode useStore useStore}\n * where the type of the Redux `store` is predefined.\n *\n * This allows you to set the `store` type once, eliminating the need to\n * specify it with every {@linkcode useStore useStore} call.\n *\n * @returns A pre-typed `useStore` with the store type already defined.\n *\n * @example\n * ```ts\n * export const useAppStore = useStore.withTypes()\n * ```\n *\n * @template OverrideStoreType - The specific type of the Redux store that gets returned.\n *\n * @since 9.1.0\n */\n withTypes: <\n OverrideStoreType extends StoreType,\n >() => UseStore\n}\n\n/**\n * Hook factory, which creates a `useStore` hook bound to a given context.\n *\n * @param {React.Context} [context=ReactReduxContext] Context passed to your ``.\n * @returns {Function} A `useStore` hook bound to the specified context.\n */\nexport function createStoreHook<\n StateType = unknown,\n ActionType extends Action = Action,\n>(\n // @ts-ignore\n context?: Context | null> = ReactReduxContext,\n) {\n const useReduxContext =\n context === ReactReduxContext\n ? useDefaultReduxContext\n : // @ts-ignore\n createReduxContextHook(context)\n const useStore = () => {\n const { store } = useReduxContext()\n return store\n }\n\n Object.assign(useStore, {\n withTypes: () => useStore,\n })\n\n return useStore as UseStore>\n}\n\n/**\n * A hook to access the redux store.\n *\n * @returns {any} the redux store\n *\n * @example\n *\n * import React from 'react'\n * import { useStore } from 'react-redux'\n *\n * export const ExampleComponent = () => {\n * const store = useStore()\n * return {store.getState()}
\n * }\n */\nexport const useStore = /*#__PURE__*/ createStoreHook()\n","import type { Context } from 'react'\nimport type { Action, Dispatch, UnknownAction } from 'redux'\n\nimport type { ReactReduxContextValue } from '../components/Context'\nimport { ReactReduxContext } from '../components/Context'\nimport { createStoreHook, useStore as useDefaultStore } from './useStore'\n\n/**\n * Represents a custom hook that provides a dispatch function\n * from the Redux store.\n *\n * @template DispatchType - The specific type of the dispatch function.\n *\n * @since 9.1.0\n * @public\n */\nexport interface UseDispatch<\n DispatchType extends Dispatch = Dispatch,\n> {\n /**\n * Returns the dispatch function from the Redux store.\n *\n * @returns The dispatch function from the Redux store.\n *\n * @template AppDispatch - The specific type of the dispatch function.\n */\n (): AppDispatch\n\n /**\n * Creates a \"pre-typed\" version of {@linkcode useDispatch useDispatch}\n * where the type of the `dispatch` function is predefined.\n *\n * This allows you to set the `dispatch` type once, eliminating the need to\n * specify it with every {@linkcode useDispatch useDispatch} call.\n *\n * @returns A pre-typed `useDispatch` with the dispatch type already defined.\n *\n * @example\n * ```ts\n * export const useAppDispatch = useDispatch.withTypes()\n * ```\n *\n * @template OverrideDispatchType - The specific type of the dispatch function.\n *\n * @since 9.1.0\n */\n withTypes: <\n OverrideDispatchType extends DispatchType,\n >() => UseDispatch\n}\n\n/**\n * Hook factory, which creates a `useDispatch` hook bound to a given context.\n *\n * @param {React.Context} [context=ReactReduxContext] Context passed to your ``.\n * @returns {Function} A `useDispatch` hook bound to the specified context.\n */\nexport function createDispatchHook<\n StateType = unknown,\n ActionType extends Action = UnknownAction,\n>(\n // @ts-ignore\n context?: Context | null> = ReactReduxContext,\n) {\n const useStore =\n context === ReactReduxContext ? useDefaultStore : createStoreHook(context)\n\n const useDispatch = () => {\n const store = useStore()\n return store.dispatch\n }\n\n Object.assign(useDispatch, {\n withTypes: () => useDispatch,\n })\n\n return useDispatch as UseDispatch>\n}\n\n/**\n * A hook to access the redux `dispatch` function.\n *\n * @returns {any|function} redux store's `dispatch` function\n *\n * @example\n *\n * import React, { useCallback } from 'react'\n * import { useDispatch } from 'react-redux'\n *\n * export const CounterComponent = ({ value }) => {\n * const dispatch = useDispatch()\n * const increaseCounter = useCallback(() => dispatch({ type: 'increase-counter' }), [])\n * return (\n * \n * {value}\n * \n *
\n * )\n * }\n */\nexport const useDispatch = /*#__PURE__*/ createDispatchHook()\n","// The primary entry point assumes we are working with React 18, and thus have\r\n// useSyncExternalStore available. We can import that directly from React itself.\r\n// The useSyncExternalStoreWithSelector has to be imported, but we can use the\r\n// non-shim version. This shaves off the byte size of the shim.\r\n\r\nimport * as React from 'react'\r\nimport { useSyncExternalStoreWithSelector } from 'use-sync-external-store/with-selector.js'\r\n\r\nimport { initializeUseSelector } from './hooks/useSelector'\r\nimport { initializeConnect } from './components/connect'\r\n\r\ninitializeUseSelector(useSyncExternalStoreWithSelector)\r\ninitializeConnect(React.useSyncExternalStore)\r\n\r\nexport * from './exports'\r\n","// Should be no imports here!\n\n/**\n * The sentinel value returned by producers to replace the draft with undefined.\n */\nexport const NOTHING: unique symbol = Symbol.for(\"immer-nothing\")\n\n/**\n * To let Immer treat your class instances as plain immutable objects\n * (albeit with a custom prototype), you must define either an instance property\n * or a static property on each of your custom classes.\n *\n * Otherwise, your class instance will never be drafted, which means it won't be\n * safe to mutate in a produce callback.\n */\nexport const DRAFTABLE: unique symbol = Symbol.for(\"immer-draftable\")\n\nexport const DRAFT_STATE: unique symbol = Symbol.for(\"immer-state\")\n","export const errors =\n\tprocess.env.NODE_ENV !== \"production\"\n\t\t? [\n\t\t\t\t// All error codes, starting by 0:\n\t\t\t\tfunction(plugin: string) {\n\t\t\t\t\treturn `The plugin for '${plugin}' has not been loaded into Immer. To enable the plugin, import and call \\`enable${plugin}()\\` when initializing your application.`\n\t\t\t\t},\n\t\t\t\tfunction(thing: string) {\n\t\t\t\t\treturn `produce can only be called on things that are draftable: plain objects, arrays, Map, Set or classes that are marked with '[immerable]: true'. Got '${thing}'`\n\t\t\t\t},\n\t\t\t\t\"This object has been frozen and should not be mutated\",\n\t\t\t\tfunction(data: any) {\n\t\t\t\t\treturn (\n\t\t\t\t\t\t\"Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? \" +\n\t\t\t\t\t\tdata\n\t\t\t\t\t)\n\t\t\t\t},\n\t\t\t\t\"An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.\",\n\t\t\t\t\"Immer forbids circular references\",\n\t\t\t\t\"The first or second argument to `produce` must be a function\",\n\t\t\t\t\"The third argument to `produce` must be a function or undefined\",\n\t\t\t\t\"First argument to `createDraft` must be a plain object, an array, or an immerable object\",\n\t\t\t\t\"First argument to `finishDraft` must be a draft returned by `createDraft`\",\n\t\t\t\tfunction(thing: string) {\n\t\t\t\t\treturn `'current' expects a draft, got: ${thing}`\n\t\t\t\t},\n\t\t\t\t\"Object.defineProperty() cannot be used on an Immer draft\",\n\t\t\t\t\"Object.setPrototypeOf() cannot be used on an Immer draft\",\n\t\t\t\t\"Immer only supports deleting array indices\",\n\t\t\t\t\"Immer only supports setting array indices and the 'length' property\",\n\t\t\t\tfunction(thing: string) {\n\t\t\t\t\treturn `'original' expects a draft, got: ${thing}`\n\t\t\t\t}\n\t\t\t\t// Note: if more errors are added, the errorOffset in Patches.ts should be increased\n\t\t\t\t// See Patches.ts for additional errors\n\t\t ]\n\t\t: []\n\nexport function die(error: number, ...args: any[]): never {\n\tif (process.env.NODE_ENV !== \"production\") {\n\t\tconst e = errors[error]\n\t\tconst msg = typeof e === \"function\" ? e.apply(null, args as any) : e\n\t\tthrow new Error(`[Immer] ${msg}`)\n\t}\n\tthrow new Error(\n\t\t`[Immer] minified error nr: ${error}. Full error at: https://bit.ly/3cXEKWf`\n\t)\n}\n","import {\n\tDRAFT_STATE,\n\tDRAFTABLE,\n\tObjectish,\n\tDrafted,\n\tAnyObject,\n\tAnyMap,\n\tAnySet,\n\tImmerState,\n\tArchType,\n\tdie,\n\tStrictMode\n} from \"../internal\"\n\nexport const getPrototypeOf = Object.getPrototypeOf\n\n/** Returns true if the given value is an Immer draft */\n/*#__PURE__*/\nexport function isDraft(value: any): boolean {\n\treturn !!value && !!value[DRAFT_STATE]\n}\n\n/** Returns true if the given value can be drafted by Immer */\n/*#__PURE__*/\nexport function isDraftable(value: any): boolean {\n\tif (!value) return false\n\treturn (\n\t\tisPlainObject(value) ||\n\t\tArray.isArray(value) ||\n\t\t!!value[DRAFTABLE] ||\n\t\t!!value.constructor?.[DRAFTABLE] ||\n\t\tisMap(value) ||\n\t\tisSet(value)\n\t)\n}\n\nconst objectCtorString = Object.prototype.constructor.toString()\n/*#__PURE__*/\nexport function isPlainObject(value: any): boolean {\n\tif (!value || typeof value !== \"object\") return false\n\tconst proto = getPrototypeOf(value)\n\tif (proto === null) {\n\t\treturn true\n\t}\n\tconst Ctor =\n\t\tObject.hasOwnProperty.call(proto, \"constructor\") && proto.constructor\n\n\tif (Ctor === Object) return true\n\n\treturn (\n\t\ttypeof Ctor == \"function\" &&\n\t\tFunction.toString.call(Ctor) === objectCtorString\n\t)\n}\n\n/** Get the underlying object that is represented by the given draft */\n/*#__PURE__*/\nexport function original(value: T): T | undefined\nexport function original(value: Drafted): any {\n\tif (!isDraft(value)) die(15, value)\n\treturn value[DRAFT_STATE].base_\n}\n\n/**\n * Each iterates a map, set or array.\n * Or, if any other kind of object, all of its own properties.\n * Regardless whether they are enumerable or symbols\n */\nexport function each(\n\tobj: T,\n\titer: (key: string | number, value: any, source: T) => void\n): void\nexport function each(obj: any, iter: any) {\n\tif (getArchtype(obj) === ArchType.Object) {\n\t\tReflect.ownKeys(obj).forEach(key => {\n\t\t\titer(key, obj[key], obj)\n\t\t})\n\t} else {\n\t\tobj.forEach((entry: any, index: any) => iter(index, entry, obj))\n\t}\n}\n\n/*#__PURE__*/\nexport function getArchtype(thing: any): ArchType {\n\tconst state: undefined | ImmerState = thing[DRAFT_STATE]\n\treturn state\n\t\t? state.type_\n\t\t: Array.isArray(thing)\n\t\t? ArchType.Array\n\t\t: isMap(thing)\n\t\t? ArchType.Map\n\t\t: isSet(thing)\n\t\t? ArchType.Set\n\t\t: ArchType.Object\n}\n\n/*#__PURE__*/\nexport function has(thing: any, prop: PropertyKey): boolean {\n\treturn getArchtype(thing) === ArchType.Map\n\t\t? thing.has(prop)\n\t\t: Object.prototype.hasOwnProperty.call(thing, prop)\n}\n\n/*#__PURE__*/\nexport function get(thing: AnyMap | AnyObject, prop: PropertyKey): any {\n\t// @ts-ignore\n\treturn getArchtype(thing) === ArchType.Map ? thing.get(prop) : thing[prop]\n}\n\n/*#__PURE__*/\nexport function set(thing: any, propOrOldValue: PropertyKey, value: any) {\n\tconst t = getArchtype(thing)\n\tif (t === ArchType.Map) thing.set(propOrOldValue, value)\n\telse if (t === ArchType.Set) {\n\t\tthing.add(value)\n\t} else thing[propOrOldValue] = value\n}\n\n/*#__PURE__*/\nexport function is(x: any, y: any): boolean {\n\t// From: https://github.com/facebook/fbjs/blob/c69904a511b900266935168223063dd8772dfc40/packages/fbjs/src/core/shallowEqual.js\n\tif (x === y) {\n\t\treturn x !== 0 || 1 / x === 1 / y\n\t} else {\n\t\treturn x !== x && y !== y\n\t}\n}\n\n/*#__PURE__*/\nexport function isMap(target: any): target is AnyMap {\n\treturn target instanceof Map\n}\n\n/*#__PURE__*/\nexport function isSet(target: any): target is AnySet {\n\treturn target instanceof Set\n}\n/*#__PURE__*/\nexport function latest(state: ImmerState): any {\n\treturn state.copy_ || state.base_\n}\n\n/*#__PURE__*/\nexport function shallowCopy(base: any, strict: StrictMode) {\n\tif (isMap(base)) {\n\t\treturn new Map(base)\n\t}\n\tif (isSet(base)) {\n\t\treturn new Set(base)\n\t}\n\tif (Array.isArray(base)) return Array.prototype.slice.call(base)\n\n\tconst isPlain = isPlainObject(base)\n\n\tif (strict === true || (strict === \"class_only\" && !isPlain)) {\n\t\t// Perform a strict copy\n\t\tconst descriptors = Object.getOwnPropertyDescriptors(base)\n\t\tdelete descriptors[DRAFT_STATE as any]\n\t\tlet keys = Reflect.ownKeys(descriptors)\n\t\tfor (let i = 0; i < keys.length; i++) {\n\t\t\tconst key: any = keys[i]\n\t\t\tconst desc = descriptors[key]\n\t\t\tif (desc.writable === false) {\n\t\t\t\tdesc.writable = true\n\t\t\t\tdesc.configurable = true\n\t\t\t}\n\t\t\t// like object.assign, we will read any _own_, get/set accessors. This helps in dealing\n\t\t\t// with libraries that trap values, like mobx or vue\n\t\t\t// unlike object.assign, non-enumerables will be copied as well\n\t\t\tif (desc.get || desc.set)\n\t\t\t\tdescriptors[key] = {\n\t\t\t\t\tconfigurable: true,\n\t\t\t\t\twritable: true, // could live with !!desc.set as well here...\n\t\t\t\t\tenumerable: desc.enumerable,\n\t\t\t\t\tvalue: base[key]\n\t\t\t\t}\n\t\t}\n\t\treturn Object.create(getPrototypeOf(base), descriptors)\n\t} else {\n\t\t// perform a sloppy copy\n\t\tconst proto = getPrototypeOf(base)\n\t\tif (proto !== null && isPlain) {\n\t\t\treturn {...base} // assumption: better inner class optimization than the assign below\n\t\t}\n\t\tconst obj = Object.create(proto)\n\t\treturn Object.assign(obj, base)\n\t}\n}\n\n/**\n * Freezes draftable objects. Returns the original object.\n * By default freezes shallowly, but if the second argument is `true` it will freeze recursively.\n *\n * @param obj\n * @param deep\n */\nexport function freeze(obj: T, deep?: boolean): T\nexport function freeze(obj: any, deep: boolean = false): T {\n\tif (isFrozen(obj) || isDraft(obj) || !isDraftable(obj)) return obj\n\tif (getArchtype(obj) > 1 /* Map or Set */) {\n\t\tobj.set = obj.add = obj.clear = obj.delete = dontMutateFrozenCollections as any\n\t}\n\tObject.freeze(obj)\n\tif (deep)\n\t\t// See #590, don't recurse into non-enumerable / Symbol properties when freezing\n\t\t// So use Object.entries (only string-like, enumerables) instead of each()\n\t\tObject.entries(obj).forEach(([key, value]) => freeze(value, true))\n\treturn obj\n}\n\nfunction dontMutateFrozenCollections() {\n\tdie(2)\n}\n\nexport function isFrozen(obj: any): boolean {\n\treturn Object.isFrozen(obj)\n}\n","import {\n\tImmerState,\n\tPatch,\n\tDrafted,\n\tImmerBaseState,\n\tAnyMap,\n\tAnySet,\n\tArchType,\n\tdie\n} from \"../internal\"\n\n/** Plugin utilities */\nconst plugins: {\n\tPatches?: {\n\t\tgeneratePatches_(\n\t\t\tstate: ImmerState,\n\t\t\tbasePath: PatchPath,\n\t\t\tpatches: Patch[],\n\t\t\tinversePatches: Patch[]\n\t\t): void\n\t\tgenerateReplacementPatches_(\n\t\t\tbase: any,\n\t\t\treplacement: any,\n\t\t\tpatches: Patch[],\n\t\t\tinversePatches: Patch[]\n\t\t): void\n\t\tapplyPatches_(draft: T, patches: readonly Patch[]): T\n\t}\n\tMapSet?: {\n\t\tproxyMap_(target: T, parent?: ImmerState): T\n\t\tproxySet_(target: T, parent?: ImmerState): T\n\t}\n} = {}\n\ntype Plugins = typeof plugins\n\nexport function getPlugin(\n\tpluginKey: K\n): Exclude {\n\tconst plugin = plugins[pluginKey]\n\tif (!plugin) {\n\t\tdie(0, pluginKey)\n\t}\n\t// @ts-ignore\n\treturn plugin\n}\n\nexport function loadPlugin(\n\tpluginKey: K,\n\timplementation: Plugins[K]\n): void {\n\tif (!plugins[pluginKey]) plugins[pluginKey] = implementation\n}\n/** Map / Set plugin */\n\nexport interface MapState extends ImmerBaseState {\n\ttype_: ArchType.Map\n\tcopy_: AnyMap | undefined\n\tassigned_: Map | undefined\n\tbase_: AnyMap\n\trevoked_: boolean\n\tdraft_: Drafted\n}\n\nexport interface SetState extends ImmerBaseState {\n\ttype_: ArchType.Set\n\tcopy_: AnySet | undefined\n\tbase_: AnySet\n\tdrafts_: Map // maps the original value to the draft value in the new set\n\trevoked_: boolean\n\tdraft_: Drafted\n}\n\n/** Patches plugin */\n\nexport type PatchPath = (string | number)[]\n","import {\n\tPatch,\n\tPatchListener,\n\tDrafted,\n\tImmer,\n\tDRAFT_STATE,\n\tImmerState,\n\tArchType,\n\tgetPlugin\n} from \"../internal\"\n\n/** Each scope represents a `produce` call. */\n\nexport interface ImmerScope {\n\tpatches_?: Patch[]\n\tinversePatches_?: Patch[]\n\tcanAutoFreeze_: boolean\n\tdrafts_: any[]\n\tparent_?: ImmerScope\n\tpatchListener_?: PatchListener\n\timmer_: Immer\n\tunfinalizedDrafts_: number\n}\n\nlet currentScope: ImmerScope | undefined\n\nexport function getCurrentScope() {\n\treturn currentScope!\n}\n\nfunction createScope(\n\tparent_: ImmerScope | undefined,\n\timmer_: Immer\n): ImmerScope {\n\treturn {\n\t\tdrafts_: [],\n\t\tparent_,\n\t\timmer_,\n\t\t// Whenever the modified draft contains a draft from another scope, we\n\t\t// need to prevent auto-freezing so the unowned draft can be finalized.\n\t\tcanAutoFreeze_: true,\n\t\tunfinalizedDrafts_: 0\n\t}\n}\n\nexport function usePatchesInScope(\n\tscope: ImmerScope,\n\tpatchListener?: PatchListener\n) {\n\tif (patchListener) {\n\t\tgetPlugin(\"Patches\") // assert we have the plugin\n\t\tscope.patches_ = []\n\t\tscope.inversePatches_ = []\n\t\tscope.patchListener_ = patchListener\n\t}\n}\n\nexport function revokeScope(scope: ImmerScope) {\n\tleaveScope(scope)\n\tscope.drafts_.forEach(revokeDraft)\n\t// @ts-ignore\n\tscope.drafts_ = null\n}\n\nexport function leaveScope(scope: ImmerScope) {\n\tif (scope === currentScope) {\n\t\tcurrentScope = scope.parent_\n\t}\n}\n\nexport function enterScope(immer: Immer) {\n\treturn (currentScope = createScope(currentScope, immer))\n}\n\nfunction revokeDraft(draft: Drafted) {\n\tconst state: ImmerState = draft[DRAFT_STATE]\n\tif (state.type_ === ArchType.Object || state.type_ === ArchType.Array)\n\t\tstate.revoke_()\n\telse state.revoked_ = true\n}\n","import {\n\tImmerScope,\n\tDRAFT_STATE,\n\tisDraftable,\n\tNOTHING,\n\tPatchPath,\n\teach,\n\thas,\n\tfreeze,\n\tImmerState,\n\tisDraft,\n\tSetState,\n\tset,\n\tArchType,\n\tgetPlugin,\n\tdie,\n\trevokeScope,\n\tisFrozen\n} from \"../internal\"\n\nexport function processResult(result: any, scope: ImmerScope) {\n\tscope.unfinalizedDrafts_ = scope.drafts_.length\n\tconst baseDraft = scope.drafts_![0]\n\tconst isReplaced = result !== undefined && result !== baseDraft\n\tif (isReplaced) {\n\t\tif (baseDraft[DRAFT_STATE].modified_) {\n\t\t\trevokeScope(scope)\n\t\t\tdie(4)\n\t\t}\n\t\tif (isDraftable(result)) {\n\t\t\t// Finalize the result in case it contains (or is) a subset of the draft.\n\t\t\tresult = finalize(scope, result)\n\t\t\tif (!scope.parent_) maybeFreeze(scope, result)\n\t\t}\n\t\tif (scope.patches_) {\n\t\t\tgetPlugin(\"Patches\").generateReplacementPatches_(\n\t\t\t\tbaseDraft[DRAFT_STATE].base_,\n\t\t\t\tresult,\n\t\t\t\tscope.patches_,\n\t\t\t\tscope.inversePatches_!\n\t\t\t)\n\t\t}\n\t} else {\n\t\t// Finalize the base draft.\n\t\tresult = finalize(scope, baseDraft, [])\n\t}\n\trevokeScope(scope)\n\tif (scope.patches_) {\n\t\tscope.patchListener_!(scope.patches_, scope.inversePatches_!)\n\t}\n\treturn result !== NOTHING ? result : undefined\n}\n\nfunction finalize(rootScope: ImmerScope, value: any, path?: PatchPath) {\n\t// Don't recurse in tho recursive data structures\n\tif (isFrozen(value)) return value\n\n\tconst state: ImmerState = value[DRAFT_STATE]\n\t// A plain object, might need freezing, might contain drafts\n\tif (!state) {\n\t\teach(value, (key, childValue) =>\n\t\t\tfinalizeProperty(rootScope, state, value, key, childValue, path)\n\t\t)\n\t\treturn value\n\t}\n\t// Never finalize drafts owned by another scope.\n\tif (state.scope_ !== rootScope) return value\n\t// Unmodified draft, return the (frozen) original\n\tif (!state.modified_) {\n\t\tmaybeFreeze(rootScope, state.base_, true)\n\t\treturn state.base_\n\t}\n\t// Not finalized yet, let's do that now\n\tif (!state.finalized_) {\n\t\tstate.finalized_ = true\n\t\tstate.scope_.unfinalizedDrafts_--\n\t\tconst result = state.copy_\n\t\t// Finalize all children of the copy\n\t\t// For sets we clone before iterating, otherwise we can get in endless loop due to modifying during iteration, see #628\n\t\t// To preserve insertion order in all cases we then clear the set\n\t\t// And we let finalizeProperty know it needs to re-add non-draft children back to the target\n\t\tlet resultEach = result\n\t\tlet isSet = false\n\t\tif (state.type_ === ArchType.Set) {\n\t\t\tresultEach = new Set(result)\n\t\t\tresult.clear()\n\t\t\tisSet = true\n\t\t}\n\t\teach(resultEach, (key, childValue) =>\n\t\t\tfinalizeProperty(rootScope, state, result, key, childValue, path, isSet)\n\t\t)\n\t\t// everything inside is frozen, we can freeze here\n\t\tmaybeFreeze(rootScope, result, false)\n\t\t// first time finalizing, let's create those patches\n\t\tif (path && rootScope.patches_) {\n\t\t\tgetPlugin(\"Patches\").generatePatches_(\n\t\t\t\tstate,\n\t\t\t\tpath,\n\t\t\t\trootScope.patches_,\n\t\t\t\trootScope.inversePatches_!\n\t\t\t)\n\t\t}\n\t}\n\treturn state.copy_\n}\n\nfunction finalizeProperty(\n\trootScope: ImmerScope,\n\tparentState: undefined | ImmerState,\n\ttargetObject: any,\n\tprop: string | number,\n\tchildValue: any,\n\trootPath?: PatchPath,\n\ttargetIsSet?: boolean\n) {\n\tif (process.env.NODE_ENV !== \"production\" && childValue === targetObject)\n\t\tdie(5)\n\tif (isDraft(childValue)) {\n\t\tconst path =\n\t\t\trootPath &&\n\t\t\tparentState &&\n\t\t\tparentState!.type_ !== ArchType.Set && // Set objects are atomic since they have no keys.\n\t\t\t!has((parentState as Exclude).assigned_!, prop) // Skip deep patches for assigned keys.\n\t\t\t\t? rootPath!.concat(prop)\n\t\t\t\t: undefined\n\t\t// Drafts owned by `scope` are finalized here.\n\t\tconst res = finalize(rootScope, childValue, path)\n\t\tset(targetObject, prop, res)\n\t\t// Drafts from another scope must prevented to be frozen\n\t\t// if we got a draft back from finalize, we're in a nested produce and shouldn't freeze\n\t\tif (isDraft(res)) {\n\t\t\trootScope.canAutoFreeze_ = false\n\t\t} else return\n\t} else if (targetIsSet) {\n\t\ttargetObject.add(childValue)\n\t}\n\t// Search new objects for unfinalized drafts. Frozen objects should never contain drafts.\n\tif (isDraftable(childValue) && !isFrozen(childValue)) {\n\t\tif (!rootScope.immer_.autoFreeze_ && rootScope.unfinalizedDrafts_ < 1) {\n\t\t\t// optimization: if an object is not a draft, and we don't have to\n\t\t\t// deepfreeze everything, and we are sure that no drafts are left in the remaining object\n\t\t\t// cause we saw and finalized all drafts already; we can stop visiting the rest of the tree.\n\t\t\t// This benefits especially adding large data tree's without further processing.\n\t\t\t// See add-data.js perf test\n\t\t\treturn\n\t\t}\n\t\tfinalize(rootScope, childValue)\n\t\t// Immer deep freezes plain objects, so if there is no parent state, we freeze as well\n\t\t// Per #590, we never freeze symbolic properties. Just to make sure don't accidentally interfere\n\t\t// with other frameworks.\n\t\tif (\n\t\t\t(!parentState || !parentState.scope_.parent_) &&\n\t\t\ttypeof prop !== \"symbol\" &&\n\t\t\tObject.prototype.propertyIsEnumerable.call(targetObject, prop)\n\t\t)\n\t\t\tmaybeFreeze(rootScope, childValue)\n\t}\n}\n\nfunction maybeFreeze(scope: ImmerScope, value: any, deep = false) {\n\t// we never freeze for a non-root scope; as it would prevent pruning for drafts inside wrapping objects\n\tif (!scope.parent_ && scope.immer_.autoFreeze_ && scope.canAutoFreeze_) {\n\t\tfreeze(value, deep)\n\t}\n}\n","import {\n\teach,\n\thas,\n\tis,\n\tisDraftable,\n\tshallowCopy,\n\tlatest,\n\tImmerBaseState,\n\tImmerState,\n\tDrafted,\n\tAnyObject,\n\tAnyArray,\n\tObjectish,\n\tgetCurrentScope,\n\tgetPrototypeOf,\n\tDRAFT_STATE,\n\tdie,\n\tcreateProxy,\n\tArchType,\n\tImmerScope\n} from \"../internal\"\n\ninterface ProxyBaseState extends ImmerBaseState {\n\tassigned_: {\n\t\t[property: string]: boolean\n\t}\n\tparent_?: ImmerState\n\trevoke_(): void\n}\n\nexport interface ProxyObjectState extends ProxyBaseState {\n\ttype_: ArchType.Object\n\tbase_: any\n\tcopy_: any\n\tdraft_: Drafted\n}\n\nexport interface ProxyArrayState extends ProxyBaseState {\n\ttype_: ArchType.Array\n\tbase_: AnyArray\n\tcopy_: AnyArray | null\n\tdraft_: Drafted