mobx-react 8.0.0 → 9.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -0
- package/README.md +92 -5
- package/dist/mobxreact.cjs.development.js +36 -49
- package/dist/mobxreact.cjs.development.js.map +1 -1
- package/dist/mobxreact.cjs.production.min.js +1 -1
- package/dist/mobxreact.cjs.production.min.js.map +1 -1
- package/dist/mobxreact.esm.development.js +37 -50
- package/dist/mobxreact.esm.development.js.map +1 -1
- package/dist/mobxreact.esm.js +37 -50
- package/dist/mobxreact.esm.js.map +1 -1
- package/dist/mobxreact.esm.production.min.js +1 -1
- package/dist/mobxreact.esm.production.min.js.map +1 -1
- package/dist/mobxreact.umd.development.js +36 -49
- package/dist/mobxreact.umd.development.js.map +1 -1
- package/dist/mobxreact.umd.production.min.js +1 -1
- package/dist/mobxreact.umd.production.min.js.map +1 -1
- package/package.json +5 -5
- package/src/observerClass.ts +51 -67
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mobxreact.esm.production.min.js","sources":["../src/utils/utils.ts","../src/observerClass.ts","../src/observer.tsx","../src/Provider.tsx","../src/inject.ts","../src/disposeOnUnmount.ts","../src/propTypes.ts","../src/index.ts"],"sourcesContent":["export function shallowEqual(objA: any, objB: any): boolean {\n //From: https://github.com/facebook/fbjs/blob/c69904a511b900266935168223063dd8772dfc40/packages/fbjs/src/core/shallowEqual.js\n if (is(objA, objB)) {\n return true\n }\n if (typeof objA !== \"object\" || objA === null || typeof objB !== \"object\" || objB === null) {\n return false\n }\n const keysA = Object.keys(objA)\n const keysB = Object.keys(objB)\n if (keysA.length !== keysB.length) {\n return false\n }\n for (let i = 0; i < keysA.length; i++) {\n if (!Object.hasOwnProperty.call(objB, keysA[i]) || !is(objA[keysA[i]], objB[keysA[i]])) {\n return false\n }\n }\n return true\n}\n\nfunction is(x: any, y: any): boolean {\n // From: https://github.com/facebook/fbjs/blob/c69904a511b900266935168223063dd8772dfc40/packages/fbjs/src/core/shallowEqual.js\n if (x === y) {\n return x !== 0 || 1 / x === 1 / y\n } else {\n return x !== x && y !== y\n }\n}\n\n// based on https://github.com/mridgway/hoist-non-react-statics/blob/master/src/index.js\nconst hoistBlackList = {\n $$typeof: 1,\n render: 1,\n compare: 1,\n type: 1,\n childContextTypes: 1,\n contextType: 1,\n contextTypes: 1,\n defaultProps: 1,\n getDefaultProps: 1,\n getDerivedStateFromError: 1,\n getDerivedStateFromProps: 1,\n mixins: 1,\n displayName: 1,\n propTypes: 1\n}\n\nexport function copyStaticProperties(base: object, target: object): void {\n const protoProps = Object.getOwnPropertyNames(Object.getPrototypeOf(base))\n Object.getOwnPropertyNames(base).forEach(key => {\n if (!hoistBlackList[key] && protoProps.indexOf(key) === -1) {\n Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(base, key)!)\n }\n })\n}\n\n/**\n * Helper to set `prop` to `this` as non-enumerable (hidden prop)\n * @param target\n * @param prop\n * @param value\n */\nexport function setHiddenProp(target: object, prop: any, value: any): void {\n if (!Object.hasOwnProperty.call(target, prop)) {\n Object.defineProperty(target, prop, {\n enumerable: false,\n configurable: true,\n writable: true,\n value\n })\n } else {\n target[prop] = value\n }\n}\n\n/**\n * Utilities for patching componentWillUnmount, to make sure @disposeOnUnmount works correctly icm with user defined hooks\n * and the handler provided by mobx-react\n */\nconst mobxMixins = Symbol(\"patchMixins\")\nconst mobxPatchedDefinition = Symbol(\"patchedDefinition\")\n\nexport interface Mixins extends Record<string, any> {\n locks: number\n methods: Array<Function>\n}\n\nfunction getMixins(target: object, methodName: string): Mixins {\n const mixins = (target[mobxMixins] = target[mobxMixins] || {})\n const methodMixins = (mixins[methodName] = mixins[methodName] || {})\n methodMixins.locks = methodMixins.locks || 0\n methodMixins.methods = methodMixins.methods || []\n return methodMixins\n}\n\nfunction wrapper(realMethod: Function, mixins: Mixins, ...args: Array<any>) {\n // locks are used to ensure that mixins are invoked only once per invocation, even on recursive calls\n mixins.locks++\n\n try {\n let retVal\n if (realMethod !== undefined && realMethod !== null) {\n retVal = realMethod.apply(this, args)\n }\n\n return retVal\n } finally {\n mixins.locks--\n if (mixins.locks === 0) {\n mixins.methods.forEach(mx => {\n mx.apply(this, args)\n })\n }\n }\n}\n\nfunction wrapFunction(realMethod: Function, mixins: Mixins): (...args: Array<any>) => any {\n const fn = function (...args: Array<any>) {\n wrapper.call(this, realMethod, mixins, ...args)\n }\n return fn\n}\n\nexport function patch(target: object, methodName: string, mixinMethod: Function): void {\n const mixins = getMixins(target, methodName)\n\n if (mixins.methods.indexOf(mixinMethod) < 0) {\n mixins.methods.push(mixinMethod)\n }\n\n const oldDefinition = Object.getOwnPropertyDescriptor(target, methodName)\n if (oldDefinition && oldDefinition[mobxPatchedDefinition]) {\n // already patched definition, do not repatch\n return\n }\n\n const originalMethod = target[methodName]\n const newDefinition = createDefinition(\n target,\n methodName,\n oldDefinition ? oldDefinition.enumerable : undefined,\n mixins,\n originalMethod\n )\n\n Object.defineProperty(target, methodName, newDefinition)\n}\n\nfunction createDefinition(\n target: object,\n methodName: string,\n enumerable: any,\n mixins: Mixins,\n originalMethod: Function\n): PropertyDescriptor {\n let wrappedFunc = wrapFunction(originalMethod, mixins)\n\n return {\n // @ts-ignore\n [mobxPatchedDefinition]: true,\n get: function () {\n return wrappedFunc\n },\n set: function (value) {\n if (this === target) {\n wrappedFunc = wrapFunction(value, mixins)\n } else {\n // when it is an instance of the prototype/a child prototype patch that particular case again separately\n // since we need to store separate values depending on wether it is the actual instance, the prototype, etc\n // e.g. the method for super might not be the same as the method for the prototype which might be not the same\n // as the method for the instance\n const newDefinition = createDefinition(this, methodName, enumerable, mixins, value)\n Object.defineProperty(this, methodName, newDefinition)\n }\n },\n configurable: true,\n enumerable: enumerable\n }\n}\n","import { PureComponent, Component, ComponentClass, ClassAttributes } from \"react\"\nimport {\n createAtom,\n _allowStateChanges,\n Reaction,\n _allowStateReadsStart,\n _allowStateReadsEnd,\n _getGlobalState,\n IAtom\n} from \"mobx\"\nimport {\n isUsingStaticRendering,\n _observerFinalizationRegistry as observerFinalizationRegistry\n} from \"mobx-react-lite\"\nimport { shallowEqual, patch } from \"./utils/utils\"\n\nconst administrationSymbol = Symbol(\"ObserverAdministration\")\nconst isMobXReactObserverSymbol = Symbol(\"isMobXReactObserver\")\n\ntype ObserverAdministration = {\n reaction: Reaction | null // also serves as disposed flag\n forceUpdate: Function | null\n mounted: boolean // we could use forceUpdate as mounted flag\n name: string\n propsAtom: IAtom\n stateAtom: IAtom\n contextAtom: IAtom\n props: any\n state: any\n context: any\n // Setting this.props causes forceUpdate, because this.props is observable.\n // forceUpdate sets this.props.\n // This flag is used to avoid the loop.\n isUpdating: boolean\n}\n\nfunction getAdministration(component: Component): ObserverAdministration {\n // We create administration lazily, because we can't patch constructor\n // and the exact moment of initialization partially depends on React internals.\n // At the time of writing this, the first thing invoked is one of the observable getter/setter (state/props/context).\n return (component[administrationSymbol] ??= {\n reaction: null,\n mounted: false,\n forceUpdate: null,\n name: getDisplayName(component.constructor as ComponentClass),\n state: undefined,\n props: undefined,\n context: undefined,\n propsAtom: createAtom(\"props\"),\n stateAtom: createAtom(\"state\"),\n contextAtom: createAtom(\"context\"),\n isUpdating: false\n })\n}\n\nexport function makeClassComponentObserver(\n componentClass: ComponentClass<any, any>\n): ComponentClass<any, any> {\n const { prototype } = componentClass\n\n if (componentClass[isMobXReactObserverSymbol]) {\n const displayName = getDisplayName(componentClass)\n console.warn(\n `The provided component class (${displayName})\n has already been declared as an observer component.`\n )\n } else {\n componentClass[isMobXReactObserverSymbol] = true\n }\n\n if (prototype.componentWillReact) {\n throw new Error(\"The componentWillReact life-cycle event is no longer supported\")\n }\n if (componentClass[\"__proto__\"] !== PureComponent) {\n if (!prototype.shouldComponentUpdate) {\n prototype.shouldComponentUpdate = observerSCU\n } else if (prototype.shouldComponentUpdate !== observerSCU) {\n // n.b. unequal check, instead of existence check, as @observer might be on superclass as well\n throw new Error(\n \"It is not allowed to use shouldComponentUpdate in observer based components.\"\n )\n }\n }\n\n // this.props and this.state are made observable, just to make sure @computed fields that\n // are defined inside the component, and which rely on state or props, re-compute if state or props change\n // (otherwise the computed wouldn't update and become stale on props change, since props are not observable)\n // However, this solution is not without it's own problems: https://github.com/mobxjs/mobx-react/issues?utf8=%E2%9C%93&q=is%3Aissue+label%3Aobservable-props-or-not+\n Object.defineProperties(prototype, {\n props: observablePropsDescriptor,\n state: observableStateDescriptor,\n context: observableContextDescriptor\n })\n\n const originalRender = prototype.render\n if (typeof originalRender !== \"function\") {\n const displayName = getDisplayName(componentClass)\n throw new Error(\n `[mobx-react] class component (${displayName}) is missing \\`render\\` method.` +\n `\\n\\`observer\\` requires \\`render\\` being a function defined on prototype.` +\n `\\n\\`render = () => {}\\` or \\`render = function() {}\\` is not supported.`\n )\n }\n\n prototype.render = function () {\n Object.defineProperty(this, \"render\", {\n // There is no safe way to replace render, therefore it's forbidden.\n configurable: false,\n writable: false,\n value: isUsingStaticRendering()\n ? originalRender\n : createReactiveRender.call(this, originalRender)\n })\n return this.render()\n }\n\n patch(prototype, \"componentDidMount\", function () {\n // `componentDidMount` may not be called at all. React can abandon the instance after `render`.\n // That's why we use finalization registry to dispose reaction created during render.\n // Happens with `<Suspend>` see #3492\n //\n // `componentDidMount` can be called immediately after `componentWillUnmount` without calling `render` in between.\n // Happens with `<StrictMode>`see #3395.\n //\n // If `componentDidMount` is called, it's guaranteed to run synchronously with render (similary to `useLayoutEffect`).\n // Therefore we don't have to worry about external (observable) state being updated before mount (no state version checking).\n //\n // Things may change: \"In the future, React will provide a feature that lets components preserve state between unmounts\"\n\n const admin = getAdministration(this)\n\n admin.mounted = true\n\n // Component instance committed, prevent reaction disposal.\n observerFinalizationRegistry.unregister(admin)\n\n // We don't set forceUpdate before mount because it requires a reference to `this`,\n // therefore `this` could NOT be garbage collected before mount,\n // preventing reaction disposal by FinalizationRegistry and leading to memory leak.\n // As an alternative we could have `admin.instanceRef = new WeakRef(this)`, but lets avoid it if possible.\n admin.forceUpdate = () => this.forceUpdate()\n\n if (!admin.reaction) {\n // 1. Instance was unmounted (reaction disposed) and immediately remounted without running render #3395.\n // 2. Reaction was disposed by finalization registry before mount. Shouldn't ever happen for class components:\n // `componentDidMount` runs synchronously after render, but our registry are deferred (can't run in between).\n // In any case we lost subscriptions to observables, so we have to create new reaction and re-render to resubscribe.\n // The reaction will be created lazily by following render.\n admin.forceUpdate()\n }\n })\n\n patch(prototype, \"componentWillUnmount\", function () {\n if (isUsingStaticRendering()) {\n return\n }\n const admin = getAdministration(this)\n admin.reaction?.dispose()\n admin.reaction = null\n admin.forceUpdate = null\n admin.mounted = false\n })\n\n return componentClass\n}\n\n// Generates a friendly name for debugging\nfunction getDisplayName(componentClass: ComponentClass) {\n return componentClass.displayName || componentClass.name || \"<component>\"\n}\n\nfunction createReactiveRender(originalRender: any) {\n const boundOriginalRender = originalRender.bind(this)\n\n const admin = getAdministration(this)\n\n function reactiveRender() {\n if (!admin.reaction) {\n // Create reaction lazily to support re-mounting #3395\n admin.reaction = createReaction(admin)\n if (!admin.mounted) {\n // React can abandon this instance and never call `componentDidMount`/`componentWillUnmount`,\n // we have to make sure reaction will be disposed.\n observerFinalizationRegistry.register(this, admin, this)\n }\n }\n\n let error: unknown = undefined\n let renderResult = undefined\n admin.reaction.track(() => {\n try {\n // TODO@major\n // Optimization: replace with _allowStateChangesStart/End (not available in mobx@6.0.0)\n renderResult = _allowStateChanges(false, boundOriginalRender)\n } catch (e) {\n error = e\n }\n })\n if (error) {\n throw error\n }\n return renderResult\n }\n\n return reactiveRender\n}\n\nfunction createReaction(admin: ObserverAdministration) {\n return new Reaction(`${admin.name}.render()`, () => {\n if (admin.isUpdating) {\n // Reaction is suppressed when setting new state/props/context,\n // this is when component is already being updated.\n return\n }\n\n if (!admin.mounted) {\n // This is neccessary to avoid react warning about calling forceUpdate on component that isn't mounted yet.\n // This happens when component is abandoned after render - our reaction is already created and reacts to changes.\n // Due to the synchronous nature of `componenDidMount`, we don't have to worry that component could eventually mount and require update.\n return\n }\n\n try {\n // forceUpdate sets new `props`, since we made it observable, it would `reportChanged`, causing a loop.\n admin.isUpdating = true\n admin.forceUpdate?.()\n } catch (error) {\n admin.reaction?.dispose()\n admin.reaction = null\n } finally {\n admin.isUpdating = false\n }\n })\n}\n\nfunction observerSCU(nextProps: ClassAttributes<any>, nextState: any): boolean {\n if (isUsingStaticRendering()) {\n console.warn(\n \"[mobx-react] It seems that a re-rendering of a React component is triggered while in static (server-side) mode. Please make sure components are rendered only once server-side.\"\n )\n }\n // update on any state changes (as is the default)\n if (this.state !== nextState) {\n return true\n }\n // update if props are shallowly not equal, inspired by PureRenderMixin\n // we could return just 'false' here, and avoid the `skipRender` checks etc\n // however, it is nicer if lifecycle events are triggered like usually,\n // so we return true here if props are shallowly modified.\n return !shallowEqual(this.props, nextProps)\n}\n\nfunction createObservablePropDescriptor(key: \"props\" | \"state\" | \"context\") {\n const atomKey = `${key}Atom`\n return {\n configurable: true,\n enumerable: true,\n get() {\n const admin = getAdministration(this)\n\n let prevReadState = _allowStateReadsStart(true)\n\n admin[atomKey].reportObserved()\n\n _allowStateReadsEnd(prevReadState)\n\n return admin[key]\n },\n set(value) {\n const admin = getAdministration(this)\n // forceUpdate issued by reaction sets new props.\n // It sets isUpdating to true to prevent loop.\n if (!admin.isUpdating && !shallowEqual(admin[key], value)) {\n admin[key] = value\n // This notifies all observers including our component,\n // but we don't want to cause `forceUpdate`, because component is already updating,\n // therefore supress component reaction.\n admin.isUpdating = true\n admin[atomKey].reportChanged()\n admin.isUpdating = false\n } else {\n admin[key] = value\n }\n }\n }\n}\n\nconst observablePropsDescriptor = createObservablePropDescriptor(\"props\")\nconst observableStateDescriptor = createObservablePropDescriptor(\"state\")\nconst observableContextDescriptor = createObservablePropDescriptor(\"context\")\n","import * as React from \"react\"\nimport { observer as observerLite } from \"mobx-react-lite\"\n\nimport { makeClassComponentObserver } from \"./observerClass\"\nimport { IReactComponent } from \"./types/IReactComponent\"\n\n/**\n * Observer function / decorator\n */\nexport function observer<T extends IReactComponent>(component: T): T {\n if (component[\"isMobxInjector\"] === true) {\n console.warn(\n \"Mobx observer: You are trying to use `observer` on a component that already has `inject`. Please apply `observer` before applying `inject`\"\n )\n }\n\n if (\n Object.prototype.isPrototypeOf.call(React.Component, component) ||\n Object.prototype.isPrototypeOf.call(React.PureComponent, component)\n ) {\n // Class component\n return makeClassComponentObserver(component as React.ComponentClass<any, any>) as T\n } else {\n // Function component\n return observerLite(component as React.FunctionComponent<any>) as T\n }\n}\n","import React from \"react\"\nimport { shallowEqual } from \"./utils/utils\"\nimport { IValueMap } from \"./types/IValueMap\"\n\nexport const MobXProviderContext = React.createContext<IValueMap>({})\n\nexport interface ProviderProps extends IValueMap {\n children: React.ReactNode\n}\n\nexport function Provider(props: ProviderProps) {\n const { children, ...stores } = props\n const parentValue = React.useContext(MobXProviderContext)\n const mutableProviderRef = React.useRef({ ...parentValue, ...stores })\n const value = mutableProviderRef.current\n\n if (__DEV__) {\n const newValue = { ...value, ...stores } // spread in previous state for the context based stores\n if (!shallowEqual(value, newValue)) {\n throw new Error(\n \"MobX Provider: The set of provided stores has changed. See: https://github.com/mobxjs/mobx-react#the-set-of-provided-stores-has-changed-error.\"\n )\n }\n }\n\n return <MobXProviderContext.Provider value={value}>{children}</MobXProviderContext.Provider>\n}\n\nProvider.displayName = \"MobXProvider\"\n","import React from \"react\"\nimport { observer } from \"./observer\"\nimport { copyStaticProperties } from \"./utils/utils\"\nimport { MobXProviderContext } from \"./Provider\"\nimport { IReactComponent } from \"./types/IReactComponent\"\nimport { IValueMap } from \"./types/IValueMap\"\nimport { IWrappedComponent } from \"./types/IWrappedComponent\"\nimport { IStoresToProps } from \"./types/IStoresToProps\"\n\n/**\n * Store Injection\n */\nfunction createStoreInjector(\n grabStoresFn: IStoresToProps,\n component: IReactComponent<any>,\n injectNames: string,\n makeReactive: boolean\n): IReactComponent<any> {\n // Support forward refs\n let Injector: IReactComponent<any> = React.forwardRef((props, ref) => {\n const newProps = { ...props }\n const context = React.useContext(MobXProviderContext)\n Object.assign(newProps, grabStoresFn(context || {}, newProps) || {})\n\n if (ref) {\n newProps.ref = ref\n }\n\n return React.createElement(component, newProps)\n })\n\n if (makeReactive) Injector = observer(Injector)\n Injector[\"isMobxInjector\"] = true // assigned late to suppress observer warning\n\n // Static fields from component should be visible on the generated Injector\n copyStaticProperties(component, Injector)\n Injector[\"wrappedComponent\"] = component\n Injector.displayName = getInjectName(component, injectNames)\n return Injector\n}\n\nfunction getInjectName(component: IReactComponent<any>, injectNames: string): string {\n let displayName\n const componentName =\n component.displayName ||\n component.name ||\n (component.constructor && component.constructor.name) ||\n \"Component\"\n if (injectNames) displayName = \"inject-with-\" + injectNames + \"(\" + componentName + \")\"\n else displayName = \"inject(\" + componentName + \")\"\n return displayName\n}\n\nfunction grabStoresByName(\n storeNames: Array<string>\n): (\n baseStores: IValueMap,\n nextProps: React.ClassAttributes<any>\n) => React.PropsWithRef<any> | undefined {\n return function (baseStores, nextProps) {\n storeNames.forEach(function (storeName) {\n if (\n storeName in nextProps // prefer props over stores\n )\n return\n if (!(storeName in baseStores))\n throw new Error(\n \"MobX injector: Store '\" +\n storeName +\n \"' is not available! Make sure it is provided by some Provider\"\n )\n nextProps[storeName] = baseStores[storeName]\n })\n return nextProps\n }\n}\n\nexport function inject(\n ...stores: Array<string>\n): <T extends IReactComponent<any>>(\n target: T\n) => T & (T extends IReactComponent<infer P> ? IWrappedComponent<P> : never)\nexport function inject<S extends IValueMap = {}, P extends IValueMap = {}, I extends IValueMap = {}, C extends IValueMap = {}>(\n fn: IStoresToProps<S, P, I, C>\n): <T extends IReactComponent>(target: T) => T & IWrappedComponent<P>\n\n/**\n * higher order component that injects stores to a child.\n * takes either a varargs list of strings, which are stores read from the context,\n * or a function that manually maps the available stores from the context to props:\n * storesToProps(mobxStores, props, context) => newProps\n */\nexport function inject(/* fn(stores, nextProps) or ...storeNames */ ...storeNames: Array<any>) {\n if (typeof arguments[0] === \"function\") {\n let grabStoresFn = arguments[0]\n return (componentClass: React.ComponentClass<any, any>) =>\n createStoreInjector(grabStoresFn, componentClass, grabStoresFn.name, true)\n } else {\n return (componentClass: React.ComponentClass<any, any>) =>\n createStoreInjector(\n grabStoresByName(storeNames),\n componentClass,\n storeNames.join(\"-\"),\n false\n )\n }\n}\n","import React from \"react\"\nimport { patch } from \"./utils/utils\"\n\nconst reactMajorVersion = Number.parseInt(React.version.split(\".\")[0])\nlet warnedAboutDisposeOnUnmountDeprecated = false\n\ntype Disposer = () => void\n\nconst protoStoreKey = Symbol(\"disposeOnUnmountProto\")\nconst instStoreKey = Symbol(\"disposeOnUnmountInst\")\n\nfunction runDisposersOnWillUnmount() {\n ;[...(this[protoStoreKey] || []), ...(this[instStoreKey] || [])].forEach(propKeyOrFunction => {\n const prop =\n typeof propKeyOrFunction === \"string\" ? this[propKeyOrFunction] : propKeyOrFunction\n if (prop !== undefined && prop !== null) {\n if (Array.isArray(prop)) prop.map(f => f())\n else prop()\n }\n })\n}\n\n/**\n * @deprecated `disposeOnUnmount` is not compatible with React 18 and higher.\n */\nexport function disposeOnUnmount(target: React.Component<any, any>, propertyKey: PropertyKey): void\n\n/**\n * @deprecated `disposeOnUnmount` is not compatible with React 18 and higher.\n */\nexport function disposeOnUnmount<TF extends Disposer | Array<Disposer>>(\n target: React.Component<any, any>,\n fn: TF\n): TF\n\n/**\n * @deprecated `disposeOnUnmount` is not compatible with React 18 and higher.\n */\nexport function disposeOnUnmount(\n target: React.Component<any, any>,\n propertyKeyOrFunction: PropertyKey | Disposer | Array<Disposer>\n): PropertyKey | Disposer | Array<Disposer> | void {\n if (Array.isArray(propertyKeyOrFunction)) {\n return propertyKeyOrFunction.map(fn => disposeOnUnmount(target, fn))\n }\n\n if (!warnedAboutDisposeOnUnmountDeprecated) {\n if (reactMajorVersion >= 18) {\n console.error(\n \"[mobx-react] disposeOnUnmount is not compatible with React 18 and higher. Don't use it.\"\n )\n } else {\n console.warn(\n \"[mobx-react] disposeOnUnmount is deprecated. It won't work correctly with React 18 and higher.\"\n )\n }\n warnedAboutDisposeOnUnmountDeprecated = true\n }\n\n const c = Object.getPrototypeOf(target).constructor\n const c2 = Object.getPrototypeOf(target.constructor)\n // Special case for react-hot-loader\n const c3 = Object.getPrototypeOf(Object.getPrototypeOf(target))\n if (\n !(\n c === React.Component ||\n c === React.PureComponent ||\n c2 === React.Component ||\n c2 === React.PureComponent ||\n c3 === React.Component ||\n c3 === React.PureComponent\n )\n ) {\n throw new Error(\n \"[mobx-react] disposeOnUnmount only supports direct subclasses of React.Component or React.PureComponent.\"\n )\n }\n\n if (\n typeof propertyKeyOrFunction !== \"string\" &&\n typeof propertyKeyOrFunction !== \"function\" &&\n !Array.isArray(propertyKeyOrFunction)\n ) {\n throw new Error(\n \"[mobx-react] disposeOnUnmount only works if the parameter is either a property key or a function.\"\n )\n }\n\n // decorator's target is the prototype, so it doesn't have any instance properties like props\n const isDecorator = typeof propertyKeyOrFunction === \"string\"\n\n // add property key / function we want run (disposed) to the store\n const componentWasAlreadyModified = !!target[protoStoreKey] || !!target[instStoreKey]\n const store = isDecorator\n ? // decorators are added to the prototype store\n target[protoStoreKey] || (target[protoStoreKey] = [])\n : // functions are added to the instance store\n target[instStoreKey] || (target[instStoreKey] = [])\n\n store.push(propertyKeyOrFunction)\n\n // tweak the component class componentWillUnmount if not done already\n if (!componentWasAlreadyModified) {\n patch(target, \"componentWillUnmount\", runDisposersOnWillUnmount)\n }\n\n // return the disposer as is if invoked as a non decorator\n if (typeof propertyKeyOrFunction !== \"string\") {\n return propertyKeyOrFunction\n }\n}\n","import { isObservableArray, isObservableObject, isObservableMap, untracked } from \"mobx\"\n\n// Copied from React.PropTypes\nfunction createChainableTypeChecker(validator: React.Validator<any>): React.Requireable<any> {\n function checkType(\n isRequired: boolean,\n props: any,\n propName: string,\n componentName: string,\n location: string,\n propFullName: string,\n ...rest: any[]\n ) {\n return untracked(() => {\n componentName = componentName || \"<<anonymous>>\"\n propFullName = propFullName || propName\n if (props[propName] == null) {\n if (isRequired) {\n const actual = props[propName] === null ? \"null\" : \"undefined\"\n return new Error(\n \"The \" +\n location +\n \" `\" +\n propFullName +\n \"` is marked as required \" +\n \"in `\" +\n componentName +\n \"`, but its value is `\" +\n actual +\n \"`.\"\n )\n }\n return null\n } else {\n // @ts-ignore rest arg is necessary for some React internals - fails tests otherwise\n return validator(props, propName, componentName, location, propFullName, ...rest)\n }\n })\n }\n\n const chainedCheckType: any = checkType.bind(null, false)\n // Add isRequired to satisfy Requirable\n chainedCheckType.isRequired = checkType.bind(null, true)\n return chainedCheckType\n}\n\n// Copied from React.PropTypes\nfunction isSymbol(propType: any, propValue: any): boolean {\n // Native Symbol.\n if (propType === \"symbol\") {\n return true\n }\n\n // 19.4.3.5 Symbol.prototype[@@toStringTag] === 'Symbol'\n if (propValue[\"@@toStringTag\"] === \"Symbol\") {\n return true\n }\n\n // Fallback for non-spec compliant Symbols which are polyfilled.\n if (typeof Symbol === \"function\" && propValue instanceof Symbol) {\n return true\n }\n\n return false\n}\n\n// Copied from React.PropTypes\nfunction getPropType(propValue: any): string {\n const propType = typeof propValue\n if (Array.isArray(propValue)) {\n return \"array\"\n }\n if (propValue instanceof RegExp) {\n // Old webkits (at least until Android 4.0) return 'function' rather than\n // 'object' for typeof a RegExp. We'll normalize this here so that /bla/\n // passes PropTypes.object.\n return \"object\"\n }\n if (isSymbol(propType, propValue)) {\n return \"symbol\"\n }\n return propType\n}\n\n// This handles more types than `getPropType`. Only used for error messages.\n// Copied from React.PropTypes\nfunction getPreciseType(propValue: any): string {\n const propType = getPropType(propValue)\n if (propType === \"object\") {\n if (propValue instanceof Date) {\n return \"date\"\n } else if (propValue instanceof RegExp) {\n return \"regexp\"\n }\n }\n return propType\n}\n\nfunction createObservableTypeCheckerCreator(\n allowNativeType: any,\n mobxType: any\n): React.Requireable<any> {\n return createChainableTypeChecker((props, propName, componentName, location, propFullName) => {\n return untracked(() => {\n if (allowNativeType) {\n if (getPropType(props[propName]) === mobxType.toLowerCase()) return null\n }\n let mobxChecker\n switch (mobxType) {\n case \"Array\":\n mobxChecker = isObservableArray\n break\n case \"Object\":\n mobxChecker = isObservableObject\n break\n case \"Map\":\n mobxChecker = isObservableMap\n break\n default:\n throw new Error(`Unexpected mobxType: ${mobxType}`)\n }\n const propValue = props[propName]\n if (!mobxChecker(propValue)) {\n const preciseType = getPreciseType(propValue)\n const nativeTypeExpectationMessage = allowNativeType\n ? \" or javascript `\" + mobxType.toLowerCase() + \"`\"\n : \"\"\n return new Error(\n \"Invalid prop `\" +\n propFullName +\n \"` of type `\" +\n preciseType +\n \"` supplied to\" +\n \" `\" +\n componentName +\n \"`, expected `mobx.Observable\" +\n mobxType +\n \"`\" +\n nativeTypeExpectationMessage +\n \".\"\n )\n }\n return null\n })\n })\n}\n\nfunction createObservableArrayOfTypeChecker(\n allowNativeType: boolean,\n typeChecker: React.Validator<any>\n) {\n return createChainableTypeChecker(\n (props, propName, componentName, location, propFullName, ...rest) => {\n return untracked(() => {\n if (typeof typeChecker !== \"function\") {\n return new Error(\n \"Property `\" +\n propFullName +\n \"` of component `\" +\n componentName +\n \"` has \" +\n \"invalid PropType notation.\"\n )\n } else {\n let error = createObservableTypeCheckerCreator(allowNativeType, \"Array\")(\n props,\n propName,\n componentName,\n location,\n propFullName\n )\n\n if (error instanceof Error) return error\n const propValue = props[propName]\n for (let i = 0; i < propValue.length; i++) {\n error = (typeChecker as React.Validator<any>)(\n propValue,\n i as any,\n componentName,\n location,\n propFullName + \"[\" + i + \"]\",\n ...rest\n )\n if (error instanceof Error) return error\n }\n\n return null\n }\n })\n }\n )\n}\n\nconst observableArray = createObservableTypeCheckerCreator(false, \"Array\")\nconst observableArrayOf = createObservableArrayOfTypeChecker.bind(null, false)\nconst observableMap = createObservableTypeCheckerCreator(false, \"Map\")\nconst observableObject = createObservableTypeCheckerCreator(false, \"Object\")\nconst arrayOrObservableArray = createObservableTypeCheckerCreator(true, \"Array\")\nconst arrayOrObservableArrayOf = createObservableArrayOfTypeChecker.bind(null, true)\nconst objectOrObservableObject = createObservableTypeCheckerCreator(true, \"Object\")\n\nexport const PropTypes = {\n observableArray,\n observableArrayOf,\n observableMap,\n observableObject,\n arrayOrObservableArray,\n arrayOrObservableArrayOf,\n objectOrObservableObject\n}\n","import { observable } from \"mobx\"\nimport { Component } from \"react\"\n\nif (!Component) {\n throw new Error(\"mobx-react requires React to be available\")\n}\n\nif (!observable) {\n throw new Error(\"mobx-react requires mobx to be available\")\n}\n\nexport {\n Observer,\n useObserver,\n useAsObservableSource,\n useLocalStore,\n isUsingStaticRendering,\n useStaticRendering,\n enableStaticRendering,\n observerBatching,\n useLocalObservable\n} from \"mobx-react-lite\"\n\nexport { observer } from \"./observer\"\n\nexport { MobXProviderContext, Provider, ProviderProps } from \"./Provider\"\nexport { inject } from \"./inject\"\nexport { disposeOnUnmount } from \"./disposeOnUnmount\"\nexport { PropTypes } from \"./propTypes\"\nexport { IWrappedComponent } from \"./types/IWrappedComponent\"\n"],"names":["shallowEqual","objA","objB","is","keysA","Object","keys","keysB","length","i","hasOwnProperty","call","x","y","hoistBlackList","$$typeof","render","compare","type","childContextTypes","contextType","contextTypes","defaultProps","getDefaultProps","getDerivedStateFromError","getDerivedStateFromProps","mixins","displayName","propTypes","mobxMixins","Symbol","mobxPatchedDefinition","wrapper","realMethod","args","locks","retVal","apply","this","methods","forEach","mx","_this","wrapFunction","patch","target","methodName","mixinMethod","methodMixins","getMixins","indexOf","push","oldDefinition","getOwnPropertyDescriptor","newDefinition","createDefinition","enumerable","originalMethod","wrappedFunc","get","set","value","defineProperty","configurable","undefined","administrationSymbol","isMobXReactObserverSymbol","getAdministration","component","reaction","mounted","forceUpdate","name","getDisplayName","constructor","state","props","context","propsAtom","createAtom","stateAtom","contextAtom","isUpdating","componentClass","createReactiveRender","originalRender","boundOriginalRender","bind","admin","Reaction","error","_admin$reaction2","dispose","createReaction","observerFinalizationRegistry","register","renderResult","track","_allowStateChanges","e","observerSCU","nextProps","nextState","isUsingStaticRendering","console","warn","createObservablePropDescriptor","key","atomKey","prevReadState","_allowStateReadsStart","reportObserved","_allowStateReadsEnd","reportChanged","observablePropsDescriptor","observableStateDescriptor","observableContextDescriptor","observer","prototype","isPrototypeOf","React","componentWillReact","Error","PureComponent","shouldComponentUpdate","defineProperties","writable","unregister","_admin$reaction","makeClassComponentObserver","observerLite","MobXProviderContext","createContext","Provider","children","stores","parentValue","useContext","mutableProviderRef","useRef","current","createStoreInjector","grabStoresFn","injectNames","makeReactive","base","protoProps","Injector","forwardRef","ref","newProps","assign","createElement","getOwnPropertyNames","getPrototypeOf","componentName","getInjectName","grabStoresByName","storeNames","baseStores","storeName","inject","arguments","join","reactMajorVersion","Number","parseInt","version","split","warnedAboutDisposeOnUnmountDeprecated","protoStoreKey","instStoreKey","runDisposersOnWillUnmount","propKeyOrFunction","prop","Array","isArray","map","f","disposeOnUnmount","propertyKeyOrFunction","fn","c","c2","c3","Component","componentWasAlreadyModified","createChainableTypeChecker","validator","checkType","isRequired","propName","location","propFullName","rest","untracked","chainedCheckType","getPropType","propValue","propType","RegExp","isSymbol","createObservableTypeCheckerCreator","allowNativeType","mobxType","toLowerCase","mobxChecker","isObservableArray","isObservableObject","isObservableMap","preciseType","Date","getPreciseType","nativeTypeExpectationMessage","createObservableArrayOfTypeChecker","typeChecker","PropTypes","observableArray","observableArrayOf","observableMap","observableObject","arrayOrObservableArray","arrayOrObservableArrayOf","objectOrObservableObject","observable"],"mappings":"okBAAgBA,EAAaC,EAAWC,GAEpC,GAAIC,EAAGF,EAAMC,GACT,OAAO,EAEX,GAAoB,iBAATD,GAA8B,OAATA,GAAiC,iBAATC,GAA8B,OAATA,EACzE,OAAO,EAEX,IAAME,EAAQC,OAAOC,KAAKL,GACpBM,EAAQF,OAAOC,KAAKJ,GAC1B,GAAIE,EAAMI,SAAWD,EAAMC,OACvB,OAAO,EAEX,IAAK,IAAIC,EAAI,EAAGA,EAAIL,EAAMI,OAAQC,IAC9B,IA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,"file":"mobxreact.esm.production.min.js","sources":["../src/utils/utils.ts","../src/observerClass.ts","../src/observer.tsx","../src/Provider.tsx","../src/inject.ts","../src/disposeOnUnmount.ts","../src/propTypes.ts","../src/index.ts"],"sourcesContent":["export function shallowEqual(objA: any, objB: any): boolean {\n //From: https://github.com/facebook/fbjs/blob/c69904a511b900266935168223063dd8772dfc40/packages/fbjs/src/core/shallowEqual.js\n if (is(objA, objB)) {\n return true\n }\n if (typeof objA !== \"object\" || objA === null || typeof objB !== \"object\" || objB === null) {\n return false\n }\n const keysA = Object.keys(objA)\n const keysB = Object.keys(objB)\n if (keysA.length !== keysB.length) {\n return false\n }\n for (let i = 0; i < keysA.length; i++) {\n if (!Object.hasOwnProperty.call(objB, keysA[i]) || !is(objA[keysA[i]], objB[keysA[i]])) {\n return false\n }\n }\n return true\n}\n\nfunction is(x: any, y: any): boolean {\n // From: https://github.com/facebook/fbjs/blob/c69904a511b900266935168223063dd8772dfc40/packages/fbjs/src/core/shallowEqual.js\n if (x === y) {\n return x !== 0 || 1 / x === 1 / y\n } else {\n return x !== x && y !== y\n }\n}\n\n// based on https://github.com/mridgway/hoist-non-react-statics/blob/master/src/index.js\nconst hoistBlackList = {\n $$typeof: 1,\n render: 1,\n compare: 1,\n type: 1,\n childContextTypes: 1,\n contextType: 1,\n contextTypes: 1,\n defaultProps: 1,\n getDefaultProps: 1,\n getDerivedStateFromError: 1,\n getDerivedStateFromProps: 1,\n mixins: 1,\n displayName: 1,\n propTypes: 1\n}\n\nexport function copyStaticProperties(base: object, target: object): void {\n const protoProps = Object.getOwnPropertyNames(Object.getPrototypeOf(base))\n Object.getOwnPropertyNames(base).forEach(key => {\n if (!hoistBlackList[key] && protoProps.indexOf(key) === -1) {\n Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(base, key)!)\n }\n })\n}\n\n/**\n * Helper to set `prop` to `this` as non-enumerable (hidden prop)\n * @param target\n * @param prop\n * @param value\n */\nexport function setHiddenProp(target: object, prop: any, value: any): void {\n if (!Object.hasOwnProperty.call(target, prop)) {\n Object.defineProperty(target, prop, {\n enumerable: false,\n configurable: true,\n writable: true,\n value\n })\n } else {\n target[prop] = value\n }\n}\n\n/**\n * Utilities for patching componentWillUnmount, to make sure @disposeOnUnmount works correctly icm with user defined hooks\n * and the handler provided by mobx-react\n */\nconst mobxMixins = Symbol(\"patchMixins\")\nconst mobxPatchedDefinition = Symbol(\"patchedDefinition\")\n\nexport interface Mixins extends Record<string, any> {\n locks: number\n methods: Array<Function>\n}\n\nfunction getMixins(target: object, methodName: string): Mixins {\n const mixins = (target[mobxMixins] = target[mobxMixins] || {})\n const methodMixins = (mixins[methodName] = mixins[methodName] || {})\n methodMixins.locks = methodMixins.locks || 0\n methodMixins.methods = methodMixins.methods || []\n return methodMixins\n}\n\nfunction wrapper(realMethod: Function, mixins: Mixins, ...args: Array<any>) {\n // locks are used to ensure that mixins are invoked only once per invocation, even on recursive calls\n mixins.locks++\n\n try {\n let retVal\n if (realMethod !== undefined && realMethod !== null) {\n retVal = realMethod.apply(this, args)\n }\n\n return retVal\n } finally {\n mixins.locks--\n if (mixins.locks === 0) {\n mixins.methods.forEach(mx => {\n mx.apply(this, args)\n })\n }\n }\n}\n\nfunction wrapFunction(realMethod: Function, mixins: Mixins): (...args: Array<any>) => any {\n const fn = function (...args: Array<any>) {\n wrapper.call(this, realMethod, mixins, ...args)\n }\n return fn\n}\n\nexport function patch(target: object, methodName: string, mixinMethod: Function): void {\n const mixins = getMixins(target, methodName)\n\n if (mixins.methods.indexOf(mixinMethod) < 0) {\n mixins.methods.push(mixinMethod)\n }\n\n const oldDefinition = Object.getOwnPropertyDescriptor(target, methodName)\n if (oldDefinition && oldDefinition[mobxPatchedDefinition]) {\n // already patched definition, do not repatch\n return\n }\n\n const originalMethod = target[methodName]\n const newDefinition = createDefinition(\n target,\n methodName,\n oldDefinition ? oldDefinition.enumerable : undefined,\n mixins,\n originalMethod\n )\n\n Object.defineProperty(target, methodName, newDefinition)\n}\n\nfunction createDefinition(\n target: object,\n methodName: string,\n enumerable: any,\n mixins: Mixins,\n originalMethod: Function\n): PropertyDescriptor {\n let wrappedFunc = wrapFunction(originalMethod, mixins)\n\n return {\n // @ts-ignore\n [mobxPatchedDefinition]: true,\n get: function () {\n return wrappedFunc\n },\n set: function (value) {\n if (this === target) {\n wrappedFunc = wrapFunction(value, mixins)\n } else {\n // when it is an instance of the prototype/a child prototype patch that particular case again separately\n // since we need to store separate values depending on wether it is the actual instance, the prototype, etc\n // e.g. the method for super might not be the same as the method for the prototype which might be not the same\n // as the method for the instance\n const newDefinition = createDefinition(this, methodName, enumerable, mixins, value)\n Object.defineProperty(this, methodName, newDefinition)\n }\n },\n configurable: true,\n enumerable: enumerable\n }\n}\n","import { PureComponent, Component, ComponentClass, ClassAttributes } from \"react\"\nimport {\n _allowStateChanges,\n Reaction,\n _allowStateReadsStart,\n _allowStateReadsEnd,\n _getGlobalState\n} from \"mobx\"\nimport {\n isUsingStaticRendering,\n _observerFinalizationRegistry as observerFinalizationRegistry\n} from \"mobx-react-lite\"\nimport { shallowEqual, patch } from \"./utils/utils\"\n\nconst administrationSymbol = Symbol(\"ObserverAdministration\")\nconst isMobXReactObserverSymbol = Symbol(\"isMobXReactObserver\")\n\nlet observablePropDescriptors: PropertyDescriptorMap\nif (__DEV__) {\n observablePropDescriptors = {\n props: createObservablePropDescriptor(\"props\"),\n state: createObservablePropDescriptor(\"state\"),\n context: createObservablePropDescriptor(\"context\")\n }\n}\n\ntype ObserverAdministration = {\n reaction: Reaction | null // also serves as disposed flag\n forceUpdate: Function | null\n mounted: boolean // we could use forceUpdate as mounted flag\n reactionInvalidatedBeforeMount: boolean\n name: string\n // Used only on __DEV__\n props: any\n state: any\n context: any\n}\n\nfunction getAdministration(component: Component): ObserverAdministration {\n // We create administration lazily, because we can't patch constructor\n // and the exact moment of initialization partially depends on React internals.\n // At the time of writing this, the first thing invoked is one of the observable getter/setter (state/props/context).\n return (component[administrationSymbol] ??= {\n reaction: null,\n mounted: false,\n reactionInvalidatedBeforeMount: false,\n forceUpdate: null,\n name: getDisplayName(component.constructor as ComponentClass),\n state: undefined,\n props: undefined,\n context: undefined\n })\n}\n\nexport function makeClassComponentObserver(\n componentClass: ComponentClass<any, any>\n): ComponentClass<any, any> {\n const { prototype } = componentClass\n\n if (componentClass[isMobXReactObserverSymbol]) {\n const displayName = getDisplayName(componentClass)\n throw new Error(\n `The provided component class (${displayName}) has already been declared as an observer component.`\n )\n } else {\n componentClass[isMobXReactObserverSymbol] = true\n }\n\n if (prototype.componentWillReact) {\n throw new Error(\"The componentWillReact life-cycle event is no longer supported\")\n }\n if (componentClass[\"__proto__\"] !== PureComponent) {\n if (!prototype.shouldComponentUpdate) {\n prototype.shouldComponentUpdate = observerSCU\n } else if (prototype.shouldComponentUpdate !== observerSCU) {\n // n.b. unequal check, instead of existence check, as @observer might be on superclass as well\n throw new Error(\n \"It is not allowed to use shouldComponentUpdate in observer based components.\"\n )\n }\n }\n\n if (__DEV__) {\n Object.defineProperties(prototype, observablePropDescriptors)\n }\n\n const originalRender = prototype.render\n if (typeof originalRender !== \"function\") {\n const displayName = getDisplayName(componentClass)\n throw new Error(\n `[mobx-react] class component (${displayName}) is missing \\`render\\` method.` +\n `\\n\\`observer\\` requires \\`render\\` being a function defined on prototype.` +\n `\\n\\`render = () => {}\\` or \\`render = function() {}\\` is not supported.`\n )\n }\n\n prototype.render = function () {\n Object.defineProperty(this, \"render\", {\n // There is no safe way to replace render, therefore it's forbidden.\n configurable: false,\n writable: false,\n value: isUsingStaticRendering()\n ? originalRender\n : createReactiveRender.call(this, originalRender)\n })\n return this.render()\n }\n\n const originalComponentDidMount = prototype.componentDidMount\n prototype.componentDidMount = function () {\n if (__DEV__ && this.componentDidMount !== Object.getPrototypeOf(this).componentDidMount) {\n const displayName = getDisplayName(componentClass)\n throw new Error(\n `[mobx-react] \\`observer(${displayName}).componentDidMount\\` must be defined on prototype.` +\n `\\n\\`componentDidMount = () => {}\\` or \\`componentDidMount = function() {}\\` is not supported.`\n )\n }\n\n // `componentDidMount` may not be called at all. React can abandon the instance after `render`.\n // That's why we use finalization registry to dispose reaction created during render.\n // Happens with `<Suspend>` see #3492\n //\n // `componentDidMount` can be called immediately after `componentWillUnmount` without calling `render` in between.\n // Happens with `<StrictMode>`see #3395.\n //\n // If `componentDidMount` is called, it's guaranteed to run synchronously with render (similary to `useLayoutEffect`).\n // Therefore we don't have to worry about external (observable) state being updated before mount (no state version checking).\n //\n // Things may change: \"In the future, React will provide a feature that lets components preserve state between unmounts\"\n\n const admin = getAdministration(this)\n\n admin.mounted = true\n\n // Component instance committed, prevent reaction disposal.\n observerFinalizationRegistry.unregister(admin)\n\n // We don't set forceUpdate before mount because it requires a reference to `this`,\n // therefore `this` could NOT be garbage collected before mount,\n // preventing reaction disposal by FinalizationRegistry and leading to memory leak.\n // As an alternative we could have `admin.instanceRef = new WeakRef(this)`, but lets avoid it if possible.\n admin.forceUpdate = () => this.forceUpdate()\n\n if (!admin.reaction || admin.reactionInvalidatedBeforeMount) {\n // Missing reaction:\n // 1. Instance was unmounted (reaction disposed) and immediately remounted without running render #3395.\n // 2. Reaction was disposed by finalization registry before mount. Shouldn't ever happen for class components:\n // `componentDidMount` runs synchronously after render, but our registry are deferred (can't run in between).\n // In any case we lost subscriptions to observables, so we have to create new reaction and re-render to resubscribe.\n // The reaction will be created lazily by following render.\n\n // Reaction invalidated before mount:\n // 1. A descendant's `componenDidMount` invalidated it's parent #3730\n\n admin.forceUpdate()\n }\n return originalComponentDidMount?.apply(this, arguments)\n }\n\n // TODO@major Overly complicated \"patch\" is only needed to support the deprecated @disposeOnUnmount\n patch(prototype, \"componentWillUnmount\", function () {\n if (isUsingStaticRendering()) {\n return\n }\n const admin = getAdministration(this)\n admin.reaction?.dispose()\n admin.reaction = null\n admin.forceUpdate = null\n admin.mounted = false\n admin.reactionInvalidatedBeforeMount = false\n })\n\n return componentClass\n}\n\n// Generates a friendly name for debugging\nfunction getDisplayName(componentClass: ComponentClass) {\n return componentClass.displayName || componentClass.name || \"<component>\"\n}\n\nfunction createReactiveRender(originalRender: any) {\n const boundOriginalRender = originalRender.bind(this)\n\n const admin = getAdministration(this)\n\n function reactiveRender() {\n if (!admin.reaction) {\n // Create reaction lazily to support re-mounting #3395\n admin.reaction = createReaction(admin)\n if (!admin.mounted) {\n // React can abandon this instance and never call `componentDidMount`/`componentWillUnmount`,\n // we have to make sure reaction will be disposed.\n observerFinalizationRegistry.register(this, admin, this)\n }\n }\n\n let error: unknown = undefined\n let renderResult = undefined\n admin.reaction.track(() => {\n try {\n // TODO@major\n // Optimization: replace with _allowStateChangesStart/End (not available in mobx@6.0.0)\n renderResult = _allowStateChanges(false, boundOriginalRender)\n } catch (e) {\n error = e\n }\n })\n if (error) {\n throw error\n }\n return renderResult\n }\n\n return reactiveRender\n}\n\nfunction createReaction(admin: ObserverAdministration) {\n return new Reaction(`${admin.name}.render()`, () => {\n if (!admin.mounted) {\n // This is neccessary to avoid react warning about calling forceUpdate on component that isn't mounted yet.\n // This happens when component is abandoned after render - our reaction is already created and reacts to changes.\n // `componenDidMount` runs synchronously after `render`, so unlike functional component, there is no delay during which the reaction could be invalidated.\n // However `componentDidMount` runs AFTER it's descendants' `componentDidMount`, which CAN invalidate the reaction, see #3730. Therefore remember and forceUpdate on mount.\n admin.reactionInvalidatedBeforeMount = true\n return\n }\n\n try {\n admin.forceUpdate?.()\n } catch (error) {\n admin.reaction?.dispose()\n admin.reaction = null\n }\n })\n}\n\nfunction observerSCU(nextProps: ClassAttributes<any>, nextState: any): boolean {\n if (isUsingStaticRendering()) {\n console.warn(\n \"[mobx-react] It seems that a re-rendering of a React component is triggered while in static (server-side) mode. Please make sure components are rendered only once server-side.\"\n )\n }\n // update on any state changes (as is the default)\n if (this.state !== nextState) {\n return true\n }\n // update if props are shallowly not equal, inspired by PureRenderMixin\n // we could return just 'false' here, and avoid the `skipRender` checks etc\n // however, it is nicer if lifecycle events are triggered like usually,\n // so we return true here if props are shallowly modified.\n return !shallowEqual(this.props, nextProps)\n}\n\nfunction createObservablePropDescriptor(key: \"props\" | \"state\" | \"context\") {\n return {\n configurable: true,\n enumerable: true,\n get() {\n const admin = getAdministration(this)\n const derivation = _getGlobalState().trackingDerivation\n if (derivation && derivation !== admin.reaction) {\n throw new Error(\n `[mobx-react] Cannot read \"${admin.name}.${key}\" in a reactive context, as it isn't observable.\n Please use component lifecycle method to copy the value into a local observable first.\n See https://github.com/mobxjs/mobx/blob/main/packages/mobx-react/README.md#note-on-using-props-and-state-in-derivations`\n )\n }\n return admin[key]\n },\n set(value) {\n getAdministration(this)[key] = value\n }\n }\n}\n","import * as React from \"react\"\nimport { observer as observerLite } from \"mobx-react-lite\"\n\nimport { makeClassComponentObserver } from \"./observerClass\"\nimport { IReactComponent } from \"./types/IReactComponent\"\n\n/**\n * Observer function / decorator\n */\nexport function observer<T extends IReactComponent>(component: T): T {\n if (component[\"isMobxInjector\"] === true) {\n console.warn(\n \"Mobx observer: You are trying to use `observer` on a component that already has `inject`. Please apply `observer` before applying `inject`\"\n )\n }\n\n if (\n Object.prototype.isPrototypeOf.call(React.Component, component) ||\n Object.prototype.isPrototypeOf.call(React.PureComponent, component)\n ) {\n // Class component\n return makeClassComponentObserver(component as React.ComponentClass<any, any>) as T\n } else {\n // Function component\n return observerLite(component as React.FunctionComponent<any>) as T\n }\n}\n","import React from \"react\"\nimport { shallowEqual } from \"./utils/utils\"\nimport { IValueMap } from \"./types/IValueMap\"\n\nexport const MobXProviderContext = React.createContext<IValueMap>({})\n\nexport interface ProviderProps extends IValueMap {\n children: React.ReactNode\n}\n\nexport function Provider(props: ProviderProps) {\n const { children, ...stores } = props\n const parentValue = React.useContext(MobXProviderContext)\n const mutableProviderRef = React.useRef({ ...parentValue, ...stores })\n const value = mutableProviderRef.current\n\n if (__DEV__) {\n const newValue = { ...value, ...stores } // spread in previous state for the context based stores\n if (!shallowEqual(value, newValue)) {\n throw new Error(\n \"MobX Provider: The set of provided stores has changed. See: https://github.com/mobxjs/mobx-react#the-set-of-provided-stores-has-changed-error.\"\n )\n }\n }\n\n return <MobXProviderContext.Provider value={value}>{children}</MobXProviderContext.Provider>\n}\n\nProvider.displayName = \"MobXProvider\"\n","import React from \"react\"\nimport { observer } from \"./observer\"\nimport { copyStaticProperties } from \"./utils/utils\"\nimport { MobXProviderContext } from \"./Provider\"\nimport { IReactComponent } from \"./types/IReactComponent\"\nimport { IValueMap } from \"./types/IValueMap\"\nimport { IWrappedComponent } from \"./types/IWrappedComponent\"\nimport { IStoresToProps } from \"./types/IStoresToProps\"\n\n/**\n * Store Injection\n */\nfunction createStoreInjector(\n grabStoresFn: IStoresToProps,\n component: IReactComponent<any>,\n injectNames: string,\n makeReactive: boolean\n): IReactComponent<any> {\n // Support forward refs\n let Injector: IReactComponent<any> = React.forwardRef((props, ref) => {\n const newProps = { ...props }\n const context = React.useContext(MobXProviderContext)\n Object.assign(newProps, grabStoresFn(context || {}, newProps) || {})\n\n if (ref) {\n newProps.ref = ref\n }\n\n return React.createElement(component, newProps)\n })\n\n if (makeReactive) Injector = observer(Injector)\n Injector[\"isMobxInjector\"] = true // assigned late to suppress observer warning\n\n // Static fields from component should be visible on the generated Injector\n copyStaticProperties(component, Injector)\n Injector[\"wrappedComponent\"] = component\n Injector.displayName = getInjectName(component, injectNames)\n return Injector\n}\n\nfunction getInjectName(component: IReactComponent<any>, injectNames: string): string {\n let displayName\n const componentName =\n component.displayName ||\n component.name ||\n (component.constructor && component.constructor.name) ||\n \"Component\"\n if (injectNames) displayName = \"inject-with-\" + injectNames + \"(\" + componentName + \")\"\n else displayName = \"inject(\" + componentName + \")\"\n return displayName\n}\n\nfunction grabStoresByName(\n storeNames: Array<string>\n): (\n baseStores: IValueMap,\n nextProps: React.ClassAttributes<any>\n) => React.PropsWithRef<any> | undefined {\n return function (baseStores, nextProps) {\n storeNames.forEach(function (storeName) {\n if (\n storeName in nextProps // prefer props over stores\n )\n return\n if (!(storeName in baseStores))\n throw new Error(\n \"MobX injector: Store '\" +\n storeName +\n \"' is not available! Make sure it is provided by some Provider\"\n )\n nextProps[storeName] = baseStores[storeName]\n })\n return nextProps\n }\n}\n\nexport function inject(\n ...stores: Array<string>\n): <T extends IReactComponent<any>>(\n target: T\n) => T & (T extends IReactComponent<infer P> ? IWrappedComponent<P> : never)\nexport function inject<S extends IValueMap = {}, P extends IValueMap = {}, I extends IValueMap = {}, C extends IValueMap = {}>(\n fn: IStoresToProps<S, P, I, C>\n): <T extends IReactComponent>(target: T) => T & IWrappedComponent<P>\n\n/**\n * higher order component that injects stores to a child.\n * takes either a varargs list of strings, which are stores read from the context,\n * or a function that manually maps the available stores from the context to props:\n * storesToProps(mobxStores, props, context) => newProps\n */\nexport function inject(/* fn(stores, nextProps) or ...storeNames */ ...storeNames: Array<any>) {\n if (typeof arguments[0] === \"function\") {\n let grabStoresFn = arguments[0]\n return (componentClass: React.ComponentClass<any, any>) =>\n createStoreInjector(grabStoresFn, componentClass, grabStoresFn.name, true)\n } else {\n return (componentClass: React.ComponentClass<any, any>) =>\n createStoreInjector(\n grabStoresByName(storeNames),\n componentClass,\n storeNames.join(\"-\"),\n false\n )\n }\n}\n","import React from \"react\"\nimport { patch } from \"./utils/utils\"\n\nconst reactMajorVersion = Number.parseInt(React.version.split(\".\")[0])\nlet warnedAboutDisposeOnUnmountDeprecated = false\n\ntype Disposer = () => void\n\nconst protoStoreKey = Symbol(\"disposeOnUnmountProto\")\nconst instStoreKey = Symbol(\"disposeOnUnmountInst\")\n\nfunction runDisposersOnWillUnmount() {\n ;[...(this[protoStoreKey] || []), ...(this[instStoreKey] || [])].forEach(propKeyOrFunction => {\n const prop =\n typeof propKeyOrFunction === \"string\" ? this[propKeyOrFunction] : propKeyOrFunction\n if (prop !== undefined && prop !== null) {\n if (Array.isArray(prop)) prop.map(f => f())\n else prop()\n }\n })\n}\n\n/**\n * @deprecated `disposeOnUnmount` is not compatible with React 18 and higher.\n */\nexport function disposeOnUnmount(target: React.Component<any, any>, propertyKey: PropertyKey): void\n\n/**\n * @deprecated `disposeOnUnmount` is not compatible with React 18 and higher.\n */\nexport function disposeOnUnmount<TF extends Disposer | Array<Disposer>>(\n target: React.Component<any, any>,\n fn: TF\n): TF\n\n/**\n * @deprecated `disposeOnUnmount` is not compatible with React 18 and higher.\n */\nexport function disposeOnUnmount(\n target: React.Component<any, any>,\n propertyKeyOrFunction: PropertyKey | Disposer | Array<Disposer>\n): PropertyKey | Disposer | Array<Disposer> | void {\n if (Array.isArray(propertyKeyOrFunction)) {\n return propertyKeyOrFunction.map(fn => disposeOnUnmount(target, fn))\n }\n\n if (!warnedAboutDisposeOnUnmountDeprecated) {\n if (reactMajorVersion >= 18) {\n console.error(\n \"[mobx-react] disposeOnUnmount is not compatible with React 18 and higher. Don't use it.\"\n )\n } else {\n console.warn(\n \"[mobx-react] disposeOnUnmount is deprecated. It won't work correctly with React 18 and higher.\"\n )\n }\n warnedAboutDisposeOnUnmountDeprecated = true\n }\n\n const c = Object.getPrototypeOf(target).constructor\n const c2 = Object.getPrototypeOf(target.constructor)\n // Special case for react-hot-loader\n const c3 = Object.getPrototypeOf(Object.getPrototypeOf(target))\n if (\n !(\n c === React.Component ||\n c === React.PureComponent ||\n c2 === React.Component ||\n c2 === React.PureComponent ||\n c3 === React.Component ||\n c3 === React.PureComponent\n )\n ) {\n throw new Error(\n \"[mobx-react] disposeOnUnmount only supports direct subclasses of React.Component or React.PureComponent.\"\n )\n }\n\n if (\n typeof propertyKeyOrFunction !== \"string\" &&\n typeof propertyKeyOrFunction !== \"function\" &&\n !Array.isArray(propertyKeyOrFunction)\n ) {\n throw new Error(\n \"[mobx-react] disposeOnUnmount only works if the parameter is either a property key or a function.\"\n )\n }\n\n // decorator's target is the prototype, so it doesn't have any instance properties like props\n const isDecorator = typeof propertyKeyOrFunction === \"string\"\n\n // add property key / function we want run (disposed) to the store\n const componentWasAlreadyModified = !!target[protoStoreKey] || !!target[instStoreKey]\n const store = isDecorator\n ? // decorators are added to the prototype store\n target[protoStoreKey] || (target[protoStoreKey] = [])\n : // functions are added to the instance store\n target[instStoreKey] || (target[instStoreKey] = [])\n\n store.push(propertyKeyOrFunction)\n\n // tweak the component class componentWillUnmount if not done already\n if (!componentWasAlreadyModified) {\n patch(target, \"componentWillUnmount\", runDisposersOnWillUnmount)\n }\n\n // return the disposer as is if invoked as a non decorator\n if (typeof propertyKeyOrFunction !== \"string\") {\n return propertyKeyOrFunction\n }\n}\n","import { isObservableArray, isObservableObject, isObservableMap, untracked } from \"mobx\"\n\n// Copied from React.PropTypes\nfunction createChainableTypeChecker(validator: React.Validator<any>): React.Requireable<any> {\n function checkType(\n isRequired: boolean,\n props: any,\n propName: string,\n componentName: string,\n location: string,\n propFullName: string,\n ...rest: any[]\n ) {\n return untracked(() => {\n componentName = componentName || \"<<anonymous>>\"\n propFullName = propFullName || propName\n if (props[propName] == null) {\n if (isRequired) {\n const actual = props[propName] === null ? \"null\" : \"undefined\"\n return new Error(\n \"The \" +\n location +\n \" `\" +\n propFullName +\n \"` is marked as required \" +\n \"in `\" +\n componentName +\n \"`, but its value is `\" +\n actual +\n \"`.\"\n )\n }\n return null\n } else {\n // @ts-ignore rest arg is necessary for some React internals - fails tests otherwise\n return validator(props, propName, componentName, location, propFullName, ...rest)\n }\n })\n }\n\n const chainedCheckType: any = checkType.bind(null, false)\n // Add isRequired to satisfy Requirable\n chainedCheckType.isRequired = checkType.bind(null, true)\n return chainedCheckType\n}\n\n// Copied from React.PropTypes\nfunction isSymbol(propType: any, propValue: any): boolean {\n // Native Symbol.\n if (propType === \"symbol\") {\n return true\n }\n\n // 19.4.3.5 Symbol.prototype[@@toStringTag] === 'Symbol'\n if (propValue[\"@@toStringTag\"] === \"Symbol\") {\n return true\n }\n\n // Fallback for non-spec compliant Symbols which are polyfilled.\n if (typeof Symbol === \"function\" && propValue instanceof Symbol) {\n return true\n }\n\n return false\n}\n\n// Copied from React.PropTypes\nfunction getPropType(propValue: any): string {\n const propType = typeof propValue\n if (Array.isArray(propValue)) {\n return \"array\"\n }\n if (propValue instanceof RegExp) {\n // Old webkits (at least until Android 4.0) return 'function' rather than\n // 'object' for typeof a RegExp. We'll normalize this here so that /bla/\n // passes PropTypes.object.\n return \"object\"\n }\n if (isSymbol(propType, propValue)) {\n return \"symbol\"\n }\n return propType\n}\n\n// This handles more types than `getPropType`. Only used for error messages.\n// Copied from React.PropTypes\nfunction getPreciseType(propValue: any): string {\n const propType = getPropType(propValue)\n if (propType === \"object\") {\n if (propValue instanceof Date) {\n return \"date\"\n } else if (propValue instanceof RegExp) {\n return \"regexp\"\n }\n }\n return propType\n}\n\nfunction createObservableTypeCheckerCreator(\n allowNativeType: any,\n mobxType: any\n): React.Requireable<any> {\n return createChainableTypeChecker((props, propName, componentName, location, propFullName) => {\n return untracked(() => {\n if (allowNativeType) {\n if (getPropType(props[propName]) === mobxType.toLowerCase()) return null\n }\n let mobxChecker\n switch (mobxType) {\n case \"Array\":\n mobxChecker = isObservableArray\n break\n case \"Object\":\n mobxChecker = isObservableObject\n break\n case \"Map\":\n mobxChecker = isObservableMap\n break\n default:\n throw new Error(`Unexpected mobxType: ${mobxType}`)\n }\n const propValue = props[propName]\n if (!mobxChecker(propValue)) {\n const preciseType = getPreciseType(propValue)\n const nativeTypeExpectationMessage = allowNativeType\n ? \" or javascript `\" + mobxType.toLowerCase() + \"`\"\n : \"\"\n return new Error(\n \"Invalid prop `\" +\n propFullName +\n \"` of type `\" +\n preciseType +\n \"` supplied to\" +\n \" `\" +\n componentName +\n \"`, expected `mobx.Observable\" +\n mobxType +\n \"`\" +\n nativeTypeExpectationMessage +\n \".\"\n )\n }\n return null\n })\n })\n}\n\nfunction createObservableArrayOfTypeChecker(\n allowNativeType: boolean,\n typeChecker: React.Validator<any>\n) {\n return createChainableTypeChecker(\n (props, propName, componentName, location, propFullName, ...rest) => {\n return untracked(() => {\n if (typeof typeChecker !== \"function\") {\n return new Error(\n \"Property `\" +\n propFullName +\n \"` of component `\" +\n componentName +\n \"` has \" +\n \"invalid PropType notation.\"\n )\n } else {\n let error = createObservableTypeCheckerCreator(allowNativeType, \"Array\")(\n props,\n propName,\n componentName,\n location,\n propFullName\n )\n\n if (error instanceof Error) return error\n const propValue = props[propName]\n for (let i = 0; i < propValue.length; i++) {\n error = (typeChecker as React.Validator<any>)(\n propValue,\n i as any,\n componentName,\n location,\n propFullName + \"[\" + i + \"]\",\n ...rest\n )\n if (error instanceof Error) return error\n }\n\n return null\n }\n })\n }\n )\n}\n\nconst observableArray = createObservableTypeCheckerCreator(false, \"Array\")\nconst observableArrayOf = createObservableArrayOfTypeChecker.bind(null, false)\nconst observableMap = createObservableTypeCheckerCreator(false, \"Map\")\nconst observableObject = createObservableTypeCheckerCreator(false, \"Object\")\nconst arrayOrObservableArray = createObservableTypeCheckerCreator(true, \"Array\")\nconst arrayOrObservableArrayOf = createObservableArrayOfTypeChecker.bind(null, true)\nconst objectOrObservableObject = createObservableTypeCheckerCreator(true, \"Object\")\n\nexport const PropTypes = {\n observableArray,\n observableArrayOf,\n observableMap,\n observableObject,\n arrayOrObservableArray,\n arrayOrObservableArrayOf,\n objectOrObservableObject\n}\n","import { observable } from \"mobx\"\nimport { Component } from \"react\"\n\nif (!Component) {\n throw new Error(\"mobx-react requires React to be available\")\n}\n\nif (!observable) {\n throw new Error(\"mobx-react requires mobx to be available\")\n}\n\nexport {\n Observer,\n useObserver,\n useAsObservableSource,\n useLocalStore,\n isUsingStaticRendering,\n useStaticRendering,\n enableStaticRendering,\n observerBatching,\n useLocalObservable\n} from \"mobx-react-lite\"\n\nexport { observer } from \"./observer\"\n\nexport { MobXProviderContext, Provider, ProviderProps } from \"./Provider\"\nexport { inject } from \"./inject\"\nexport { disposeOnUnmount } from \"./disposeOnUnmount\"\nexport { PropTypes } from \"./propTypes\"\nexport { IWrappedComponent } from \"./types/IWrappedComponent\"\n"],"names":["is","x","y","hoistBlackList","$$typeof","render","compare","type","childContextTypes","contextType","contextTypes","defaultProps","getDefaultProps","getDerivedStateFromError","getDerivedStateFromProps","mixins","displayName","propTypes","mobxMixins","Symbol","mobxPatchedDefinition","wrapper","realMethod","args","locks","retVal","apply","this","methods","forEach","mx","_this","wrapFunction","call","patch","target","methodName","mixinMethod","methodMixins","getMixins","indexOf","push","oldDefinition","Object","getOwnPropertyDescriptor","newDefinition","createDefinition","enumerable","originalMethod","wrappedFunc","get","set","value","defineProperty","configurable","undefined","administrationSymbol","isMobXReactObserverSymbol","getAdministration","component","reaction","mounted","reactionInvalidatedBeforeMount","forceUpdate","name","getDisplayName","constructor","state","props","context","componentClass","createReactiveRender","originalRender","boundOriginalRender","bind","admin","Reaction","error","_admin$reaction2","dispose","createReaction","observerFinalizationRegistry","register","renderResult","track","_allowStateChanges","e","observerSCU","nextProps","nextState","isUsingStaticRendering","console","warn","objA","objB","keysA","keys","keysB","length","i","hasOwnProperty","shallowEqual","observer","prototype","isPrototypeOf","React","Error","componentWillReact","PureComponent","shouldComponentUpdate","writable","originalComponentDidMount","componentDidMount","unregister","arguments","_admin$reaction","makeClassComponentObserver","observerLite","MobXProviderContext","createContext","Provider","children","stores","parentValue","useContext","mutableProviderRef","useRef","current","createStoreInjector","grabStoresFn","injectNames","makeReactive","base","protoProps","Injector","forwardRef","ref","newProps","assign","createElement","getOwnPropertyNames","getPrototypeOf","key","componentName","getInjectName","grabStoresByName","storeNames","baseStores","storeName","inject","join","reactMajorVersion","Number","parseInt","version","split","warnedAboutDisposeOnUnmountDeprecated","protoStoreKey","instStoreKey","runDisposersOnWillUnmount","propKeyOrFunction","prop","Array","isArray","map","f","disposeOnUnmount","propertyKeyOrFunction","fn","c","c2","c3","Component","componentWasAlreadyModified","createChainableTypeChecker","validator","checkType","isRequired","propName","location","propFullName","rest","untracked","chainedCheckType","getPropType","propValue","propType","RegExp","isSymbol","createObservableTypeCheckerCreator","allowNativeType","mobxType","toLowerCase","mobxChecker","isObservableArray","isObservableObject","isObservableMap","preciseType","Date","getPreciseType","nativeTypeExpectationMessage","createObservableArrayOfTypeChecker","typeChecker","PropTypes","observableArray","observableArrayOf","observableMap","observableObject","arrayOrObservableArray","arrayOrObservableArrayOf","objectOrObservableObject","observable"],"mappings":"ufAqBA,SAASA,EAAGC,EAAQC,GAEhB,OAAID,IAAMC,EACO,IAAND,GAAW,EAAIA,GAAM,EAAIC,EAEzBD,GAAMA,GAAKC,GAAMA,EAKhC,IAAMC,EAAiB,CACnBC,SAAU,EACVC,OAAQ,EACRC,QAAS,EACTC,KAAM,EACNC,kBAAmB,EACnBC,YAAa,EACbC,aAAc,EACdC,aAAc,EACdC,gBAAiB,EACjBC,yBAA0B,EAC1BC,yBAA0B,EAC1BC,OAAQ,EACRC,YAAa,EACbC,UAAW,GAmCTC,EAAaC,OAAO,eACpBC,EAAwBD,OAAO,qBAerC,SAASE,EAAQC,EAAsBP,qCAAmBQ,mCAAAA,oBAEtDR,EAAOS,QAEP,IACI,IAAIC,EAKJ,OAJIH,MAAAA,IACAG,EAASH,EAAWI,MAAMC,KAAMJ,IAG7BE,UAEPV,EAAOS,QACc,IAAjBT,EAAOS,OACPT,EAAOa,QAAQC,SAAQ,SAAAC,GACnBA,EAAGJ,MAAMK,EAAMR,OAM/B,SAASS,EAAaV,EAAsBP,GAIxC,OAHW,sCAAaQ,2BAAAA,kBACpBF,EAAQY,WAARZ,GAAaM,KAAML,EAAYP,UAAWQ,cAKlCW,EAAMC,EAAgBC,EAAoBC,GACtD,IAAMtB,EArCV,SAAmBoB,EAAgBC,GAC/B,IAAMrB,EAAUoB,EAAOjB,GAAciB,EAAOjB,IAAe,GACrDoB,EAAgBvB,EAAOqB,GAAcrB,EAAOqB,IAAe,GAGjE,OAFAE,EAAad,MAAQc,EAAad,OAAS,EAC3Cc,EAAaV,QAAUU,EAAaV,SAAW,GACxCU,EAgCQC,CAAUJ,EAAQC,GAE7BrB,EAAOa,QAAQY,QAAQH,GAAe,GACtCtB,EAAOa,QAAQa,KAAKJ,GAGxB,IAAMK,EAAgBC,OAAOC,yBAAyBT,EAAQC,GAC9D,IAAIM,IAAiBA,E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/B,mBAAqBC,EAASC,cAAgB,IAC9C,GACN,OAAO,IAAItF,MACP,iBACI0E,EACA,cACAiB,EAHJ,kBAMItD,EACA,+BACAgD,EACA,IACAS,EACA,KAGZ,OAAO,WAKnB,SAASC,EACLX,EACAY,GAEA,OAAO5B,GACH,SAAC1G,EAAO8G,EAAUnC,EAAeoC,EAAUC,8BAAiBC,mCAAAA,oBACxD,OAAOC,GAAU,WACb,GAA2B,mBAAhBoB,EACP,OAAO,IAAIhG,MACP,aACI0E,EACA,mBACArC,EAHJ,oCAQJ,IAAIlE,EAAQgH,EAAmCC,EAAiB,QAApDD,CACRzH,EACA8G,EACAnC,EACAoC,EACAC,GAGJ,GAAIvG,aAAiB6B,MAAO,OAAO7B,EAEnC,IADA,IAAM4G,EAAYrH,EAAM8G,GACf/E,EAAI,EAAGA,EAAIsF,EAAUvF,OAAQC,IASlC,IARAtB,EAAS6H,gBACLjB,EACAtF,EACA4C,EACAoC,EACAC,EAAe,IAAMjF,EAAI,YACtBkF,eAEc3E,MAAO,OAAO7B,EAGvC,OAAO,WAO3B,IAQa8H,EAAY,CACrBC,gBAToBf,GAAmC,EAAO,SAU9DgB,kBATsBJ,EAAmC/H,KAAK,MAAM,GAUpEoI,cATkBjB,GAAmC,EAAO,OAU5DkB,iBATqBlB,GAAmC,EAAO,UAU/DmB,uBAT2BnB,GAAmC,EAAM,SAUpEoB,yBAT6BR,EAAmC/H,KAAK,MAAM,GAU3EwI,yBAT6BrB,GAAmC,EAAM,WCpM1E,IAAKjB,EACD,MAAM,IAAIlE,MAAM,6CAGpB,IAAKyG,EACD,MAAM,IAAIzG,MAAM"}
|
|
@@ -138,6 +138,14 @@
|
|
|
138
138
|
|
|
139
139
|
var administrationSymbol = /*#__PURE__*/Symbol("ObserverAdministration");
|
|
140
140
|
var isMobXReactObserverSymbol = /*#__PURE__*/Symbol("isMobXReactObserver");
|
|
141
|
+
var observablePropDescriptors;
|
|
142
|
+
{
|
|
143
|
+
observablePropDescriptors = {
|
|
144
|
+
props: /*#__PURE__*/createObservablePropDescriptor("props"),
|
|
145
|
+
state: /*#__PURE__*/createObservablePropDescriptor("state"),
|
|
146
|
+
context: /*#__PURE__*/createObservablePropDescriptor("context")
|
|
147
|
+
};
|
|
148
|
+
}
|
|
141
149
|
function getAdministration(component) {
|
|
142
150
|
var _component$administra;
|
|
143
151
|
// We create administration lazily, because we can't patch constructor
|
|
@@ -146,22 +154,19 @@
|
|
|
146
154
|
return (_component$administra = component[administrationSymbol]) != null ? _component$administra : component[administrationSymbol] = {
|
|
147
155
|
reaction: null,
|
|
148
156
|
mounted: false,
|
|
157
|
+
reactionInvalidatedBeforeMount: false,
|
|
149
158
|
forceUpdate: null,
|
|
150
159
|
name: getDisplayName(component.constructor),
|
|
151
160
|
state: undefined,
|
|
152
161
|
props: undefined,
|
|
153
|
-
context: undefined
|
|
154
|
-
propsAtom: mobx.createAtom("props"),
|
|
155
|
-
stateAtom: mobx.createAtom("state"),
|
|
156
|
-
contextAtom: mobx.createAtom("context"),
|
|
157
|
-
isUpdating: false
|
|
162
|
+
context: undefined
|
|
158
163
|
};
|
|
159
164
|
}
|
|
160
165
|
function makeClassComponentObserver(componentClass) {
|
|
161
166
|
var prototype = componentClass.prototype;
|
|
162
167
|
if (componentClass[isMobXReactObserverSymbol]) {
|
|
163
168
|
var displayName = getDisplayName(componentClass);
|
|
164
|
-
|
|
169
|
+
throw new Error("The provided component class (" + displayName + ") has already been declared as an observer component.");
|
|
165
170
|
} else {
|
|
166
171
|
componentClass[isMobXReactObserverSymbol] = true;
|
|
167
172
|
}
|
|
@@ -176,15 +181,9 @@
|
|
|
176
181
|
throw new Error("It is not allowed to use shouldComponentUpdate in observer based components.");
|
|
177
182
|
}
|
|
178
183
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
// However, this solution is not without it's own problems: https://github.com/mobxjs/mobx-react/issues?utf8=%E2%9C%93&q=is%3Aissue+label%3Aobservable-props-or-not+
|
|
183
|
-
Object.defineProperties(prototype, {
|
|
184
|
-
props: observablePropsDescriptor,
|
|
185
|
-
state: observableStateDescriptor,
|
|
186
|
-
context: observableContextDescriptor
|
|
187
|
-
});
|
|
184
|
+
{
|
|
185
|
+
Object.defineProperties(prototype, observablePropDescriptors);
|
|
186
|
+
}
|
|
188
187
|
var originalRender = prototype.render;
|
|
189
188
|
if (typeof originalRender !== "function") {
|
|
190
189
|
var _displayName = getDisplayName(componentClass);
|
|
@@ -199,8 +198,13 @@
|
|
|
199
198
|
});
|
|
200
199
|
return this.render();
|
|
201
200
|
};
|
|
202
|
-
|
|
201
|
+
var originalComponentDidMount = prototype.componentDidMount;
|
|
202
|
+
prototype.componentDidMount = function () {
|
|
203
203
|
var _this = this;
|
|
204
|
+
if ( this.componentDidMount !== Object.getPrototypeOf(this).componentDidMount) {
|
|
205
|
+
var _displayName2 = getDisplayName(componentClass);
|
|
206
|
+
throw new Error("[mobx-react] `observer(" + _displayName2 + ").componentDidMount` must be defined on prototype." + "\n`componentDidMount = () => {}` or `componentDidMount = function() {}` is not supported.");
|
|
207
|
+
}
|
|
204
208
|
// `componentDidMount` may not be called at all. React can abandon the instance after `render`.
|
|
205
209
|
// That's why we use finalization registry to dispose reaction created during render.
|
|
206
210
|
// Happens with `<Suspend>` see #3492
|
|
@@ -223,15 +227,20 @@
|
|
|
223
227
|
admin.forceUpdate = function () {
|
|
224
228
|
return _this.forceUpdate();
|
|
225
229
|
};
|
|
226
|
-
if (!admin.reaction) {
|
|
230
|
+
if (!admin.reaction || admin.reactionInvalidatedBeforeMount) {
|
|
231
|
+
// Missing reaction:
|
|
227
232
|
// 1. Instance was unmounted (reaction disposed) and immediately remounted without running render #3395.
|
|
228
233
|
// 2. Reaction was disposed by finalization registry before mount. Shouldn't ever happen for class components:
|
|
229
234
|
// `componentDidMount` runs synchronously after render, but our registry are deferred (can't run in between).
|
|
230
235
|
// In any case we lost subscriptions to observables, so we have to create new reaction and re-render to resubscribe.
|
|
231
236
|
// The reaction will be created lazily by following render.
|
|
237
|
+
// Reaction invalidated before mount:
|
|
238
|
+
// 1. A descendant's `componenDidMount` invalidated it's parent #3730
|
|
232
239
|
admin.forceUpdate();
|
|
233
240
|
}
|
|
234
|
-
|
|
241
|
+
return originalComponentDidMount == null ? void 0 : originalComponentDidMount.apply(this, arguments);
|
|
242
|
+
};
|
|
243
|
+
// TODO@major Overly complicated "patch" is only needed to support the deprecated @disposeOnUnmount
|
|
235
244
|
patch(prototype, "componentWillUnmount", function () {
|
|
236
245
|
var _admin$reaction;
|
|
237
246
|
if (mobxReactLite.isUsingStaticRendering()) {
|
|
@@ -242,6 +251,7 @@
|
|
|
242
251
|
admin.reaction = null;
|
|
243
252
|
admin.forceUpdate = null;
|
|
244
253
|
admin.mounted = false;
|
|
254
|
+
admin.reactionInvalidatedBeforeMount = false;
|
|
245
255
|
});
|
|
246
256
|
return componentClass;
|
|
247
257
|
}
|
|
@@ -282,27 +292,20 @@
|
|
|
282
292
|
}
|
|
283
293
|
function createReaction(admin) {
|
|
284
294
|
return new mobx.Reaction(admin.name + ".render()", function () {
|
|
285
|
-
if (admin.isUpdating) {
|
|
286
|
-
// Reaction is suppressed when setting new state/props/context,
|
|
287
|
-
// this is when component is already being updated.
|
|
288
|
-
return;
|
|
289
|
-
}
|
|
290
295
|
if (!admin.mounted) {
|
|
291
296
|
// This is neccessary to avoid react warning about calling forceUpdate on component that isn't mounted yet.
|
|
292
297
|
// This happens when component is abandoned after render - our reaction is already created and reacts to changes.
|
|
293
|
-
//
|
|
298
|
+
// `componenDidMount` runs synchronously after `render`, so unlike functional component, there is no delay during which the reaction could be invalidated.
|
|
299
|
+
// However `componentDidMount` runs AFTER it's descendants' `componentDidMount`, which CAN invalidate the reaction, see #3730. Therefore remember and forceUpdate on mount.
|
|
300
|
+
admin.reactionInvalidatedBeforeMount = true;
|
|
294
301
|
return;
|
|
295
302
|
}
|
|
296
303
|
try {
|
|
297
|
-
// forceUpdate sets new `props`, since we made it observable, it would `reportChanged`, causing a loop.
|
|
298
|
-
admin.isUpdating = true;
|
|
299
304
|
admin.forceUpdate == null ? void 0 : admin.forceUpdate();
|
|
300
305
|
} catch (error) {
|
|
301
306
|
var _admin$reaction2;
|
|
302
307
|
(_admin$reaction2 = admin.reaction) == null ? void 0 : _admin$reaction2.dispose();
|
|
303
308
|
admin.reaction = null;
|
|
304
|
-
} finally {
|
|
305
|
-
admin.isUpdating = false;
|
|
306
309
|
}
|
|
307
310
|
});
|
|
308
311
|
}
|
|
@@ -321,38 +324,22 @@
|
|
|
321
324
|
return !shallowEqual(this.props, nextProps);
|
|
322
325
|
}
|
|
323
326
|
function createObservablePropDescriptor(key) {
|
|
324
|
-
var atomKey = key + "Atom";
|
|
325
327
|
return {
|
|
326
328
|
configurable: true,
|
|
327
329
|
enumerable: true,
|
|
328
330
|
get: function get() {
|
|
329
331
|
var admin = getAdministration(this);
|
|
330
|
-
var
|
|
331
|
-
admin
|
|
332
|
-
|
|
332
|
+
var derivation = mobx._getGlobalState().trackingDerivation;
|
|
333
|
+
if (derivation && derivation !== admin.reaction) {
|
|
334
|
+
throw new Error("[mobx-react] Cannot read \"" + admin.name + "." + key + "\" in a reactive context, as it isn't observable.\n Please use component lifecycle method to copy the value into a local observable first.\n See https://github.com/mobxjs/mobx/blob/main/packages/mobx-react/README.md#note-on-using-props-and-state-in-derivations");
|
|
335
|
+
}
|
|
333
336
|
return admin[key];
|
|
334
337
|
},
|
|
335
338
|
set: function set(value) {
|
|
336
|
-
|
|
337
|
-
// forceUpdate issued by reaction sets new props.
|
|
338
|
-
// It sets isUpdating to true to prevent loop.
|
|
339
|
-
if (!admin.isUpdating && !shallowEqual(admin[key], value)) {
|
|
340
|
-
admin[key] = value;
|
|
341
|
-
// This notifies all observers including our component,
|
|
342
|
-
// but we don't want to cause `forceUpdate`, because component is already updating,
|
|
343
|
-
// therefore supress component reaction.
|
|
344
|
-
admin.isUpdating = true;
|
|
345
|
-
admin[atomKey].reportChanged();
|
|
346
|
-
admin.isUpdating = false;
|
|
347
|
-
} else {
|
|
348
|
-
admin[key] = value;
|
|
349
|
-
}
|
|
339
|
+
getAdministration(this)[key] = value;
|
|
350
340
|
}
|
|
351
341
|
};
|
|
352
342
|
}
|
|
353
|
-
var observablePropsDescriptor = /*#__PURE__*/createObservablePropDescriptor("props");
|
|
354
|
-
var observableStateDescriptor = /*#__PURE__*/createObservablePropDescriptor("state");
|
|
355
|
-
var observableContextDescriptor = /*#__PURE__*/createObservablePropDescriptor("context");
|
|
356
343
|
|
|
357
344
|
/**
|
|
358
345
|
* Observer function / decorator
|