mobx-react 8.0.0 → 9.0.0
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 +13 -0
- package/README.md +92 -5
- package/dist/mobxreact.cjs.development.js +27 -47
- 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 +28 -48
- package/dist/mobxreact.esm.development.js.map +1 -1
- package/dist/mobxreact.esm.js +28 -48
- 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 +27 -47
- 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 +3 -3
- package/src/observerClass.ts +39 -65
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mobxreact.umd.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","reactMajorVersion","Number","parseInt","version","split","warnedAboutDisposeOnUnmountDeprecated","protoStoreKey","instStoreKey","runDisposersOnWillUnmount","propKeyOrFunction","prop","Array","isArray","map","f","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","Component","observable","disposeOnUnmount","propertyKeyOrFunction","fn","c","c2","c3","componentWasAlreadyModified","arguments","join"],"mappings":"kXAAgBA,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,IAAKJ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
1
|
+
{"version":3,"file":"mobxreact.umd.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 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 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) {\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 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 })\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 // 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 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","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","reactMajorVersion","Number","parseInt","version","split","warnedAboutDisposeOnUnmountDeprecated","protoStoreKey","instStoreKey","runDisposersOnWillUnmount","propKeyOrFunction","prop","Array","isArray","map","f","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","Component","observable","disposeOnUnmount","propertyKeyOrFunction","fn","c","c2","c3","componentWasAlreadyModified","join"],"mappings":"yWAqBA,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,YAA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ACbO,IAAOvG,EAAMG,cAGjB,MAAM,IAAIF,MACN,4GAIR,GACqC,iBAA1BkG,GAC0B,mBAA1BA,IACN5C,MAAMC,QAAQ2C,GAEf,MAAM,IAAIlG,MACN,qGAKR,IAGMuG,IAAgC7K,EAAOuH,MAAoBvH,EAAOwH,GAexE,OAlBqD,iBAA1BgD,EAMrBxK,EAAOuH,KAAmBvH,EAAOuH,GAAiB,IAElDvH,EAAOwH,KAAkBxH,EAAOwH,GAAgB,KAEhDlH,KAAKkK,GAGNK,GACD9K,EAAMC,EAAQ,uBAAwByH,GAIL,iBAA1B+C,EACAA,OADX,kDDfmE1D,2BAAAA,kBACnE,GAA4B,mBAAjBhC,UAAU,GAAmB,CACpC,IAAIe,EAAef,UAAU,GAC7B,OAAO,SAAC5C,GAA8C,OAClD0D,EAAoBC,EAAc3D,EAAgB2D,EAAajE,MAAM,IAEzE,OAAO,SAACM,GAA8C,OAClD0D,EACIiB,EAAiBC,GACjB5E,EACA4E,EAAWgE,KAAK,MAChB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mobx-react",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "9.0.0",
|
|
4
4
|
"description": "React bindings for MobX. Create fully reactive components.",
|
|
5
5
|
"source": "src/index.ts",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
},
|
|
37
37
|
"homepage": "https://mobx.js.org",
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"mobx-react-lite": "^4.0.
|
|
39
|
+
"mobx-react-lite": "^4.0.3"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"mobx": "^6.9.0",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"mobx": "^6.9.0",
|
|
55
|
-
"mobx-react-lite": "^4.0.
|
|
55
|
+
"mobx-react-lite": "^4.0.3",
|
|
56
56
|
"expose-gc": "^1.0.0"
|
|
57
57
|
},
|
|
58
58
|
"keywords": [
|
package/src/observerClass.ts
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { PureComponent, Component, ComponentClass, ClassAttributes } from "react"
|
|
2
2
|
import {
|
|
3
|
-
createAtom,
|
|
4
3
|
_allowStateChanges,
|
|
5
4
|
Reaction,
|
|
6
5
|
_allowStateReadsStart,
|
|
7
6
|
_allowStateReadsEnd,
|
|
8
|
-
_getGlobalState
|
|
9
|
-
IAtom
|
|
7
|
+
_getGlobalState
|
|
10
8
|
} from "mobx"
|
|
11
9
|
import {
|
|
12
10
|
isUsingStaticRendering,
|
|
@@ -17,21 +15,24 @@ import { shallowEqual, patch } from "./utils/utils"
|
|
|
17
15
|
const administrationSymbol = Symbol("ObserverAdministration")
|
|
18
16
|
const isMobXReactObserverSymbol = Symbol("isMobXReactObserver")
|
|
19
17
|
|
|
18
|
+
let observablePropDescriptors: PropertyDescriptorMap
|
|
19
|
+
if (__DEV__) {
|
|
20
|
+
observablePropDescriptors = {
|
|
21
|
+
props: createObservablePropDescriptor("props"),
|
|
22
|
+
state: createObservablePropDescriptor("state"),
|
|
23
|
+
context: createObservablePropDescriptor("context")
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
20
27
|
type ObserverAdministration = {
|
|
21
28
|
reaction: Reaction | null // also serves as disposed flag
|
|
22
29
|
forceUpdate: Function | null
|
|
23
30
|
mounted: boolean // we could use forceUpdate as mounted flag
|
|
24
31
|
name: string
|
|
25
|
-
|
|
26
|
-
stateAtom: IAtom
|
|
27
|
-
contextAtom: IAtom
|
|
32
|
+
// Used only on __DEV__
|
|
28
33
|
props: any
|
|
29
34
|
state: any
|
|
30
35
|
context: any
|
|
31
|
-
// Setting this.props causes forceUpdate, because this.props is observable.
|
|
32
|
-
// forceUpdate sets this.props.
|
|
33
|
-
// This flag is used to avoid the loop.
|
|
34
|
-
isUpdating: boolean
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
function getAdministration(component: Component): ObserverAdministration {
|
|
@@ -45,11 +46,7 @@ function getAdministration(component: Component): ObserverAdministration {
|
|
|
45
46
|
name: getDisplayName(component.constructor as ComponentClass),
|
|
46
47
|
state: undefined,
|
|
47
48
|
props: undefined,
|
|
48
|
-
context: undefined
|
|
49
|
-
propsAtom: createAtom("props"),
|
|
50
|
-
stateAtom: createAtom("state"),
|
|
51
|
-
contextAtom: createAtom("context"),
|
|
52
|
-
isUpdating: false
|
|
49
|
+
context: undefined
|
|
53
50
|
})
|
|
54
51
|
}
|
|
55
52
|
|
|
@@ -60,9 +57,8 @@ export function makeClassComponentObserver(
|
|
|
60
57
|
|
|
61
58
|
if (componentClass[isMobXReactObserverSymbol]) {
|
|
62
59
|
const displayName = getDisplayName(componentClass)
|
|
63
|
-
|
|
64
|
-
`The provided component class (${displayName})
|
|
65
|
-
has already been declared as an observer component.`
|
|
60
|
+
throw new Error(
|
|
61
|
+
`The provided component class (${displayName}) has already been declared as an observer component.`
|
|
66
62
|
)
|
|
67
63
|
} else {
|
|
68
64
|
componentClass[isMobXReactObserverSymbol] = true
|
|
@@ -82,15 +78,9 @@ export function makeClassComponentObserver(
|
|
|
82
78
|
}
|
|
83
79
|
}
|
|
84
80
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
// 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+
|
|
89
|
-
Object.defineProperties(prototype, {
|
|
90
|
-
props: observablePropsDescriptor,
|
|
91
|
-
state: observableStateDescriptor,
|
|
92
|
-
context: observableContextDescriptor
|
|
93
|
-
})
|
|
81
|
+
if (__DEV__) {
|
|
82
|
+
Object.defineProperties(prototype, observablePropDescriptors)
|
|
83
|
+
}
|
|
94
84
|
|
|
95
85
|
const originalRender = prototype.render
|
|
96
86
|
if (typeof originalRender !== "function") {
|
|
@@ -114,7 +104,16 @@ export function makeClassComponentObserver(
|
|
|
114
104
|
return this.render()
|
|
115
105
|
}
|
|
116
106
|
|
|
117
|
-
|
|
107
|
+
const originalComponentDidMount = prototype.componentDidMount
|
|
108
|
+
prototype.componentDidMount = function () {
|
|
109
|
+
if (__DEV__ && this.componentDidMount !== Object.getPrototypeOf(this).componentDidMount) {
|
|
110
|
+
const displayName = getDisplayName(componentClass)
|
|
111
|
+
throw new Error(
|
|
112
|
+
`[mobx-react] \`observer(${displayName}).componentDidMount\` must be defined on prototype.` +
|
|
113
|
+
`\n\`componentDidMount = () => {}\` or \`componentDidMount = function() {}\` is not supported.`
|
|
114
|
+
)
|
|
115
|
+
}
|
|
116
|
+
|
|
118
117
|
// `componentDidMount` may not be called at all. React can abandon the instance after `render`.
|
|
119
118
|
// That's why we use finalization registry to dispose reaction created during render.
|
|
120
119
|
// Happens with `<Suspend>` see #3492
|
|
@@ -148,8 +147,10 @@ export function makeClassComponentObserver(
|
|
|
148
147
|
// The reaction will be created lazily by following render.
|
|
149
148
|
admin.forceUpdate()
|
|
150
149
|
}
|
|
151
|
-
|
|
150
|
+
return originalComponentDidMount?.apply(this, arguments)
|
|
151
|
+
}
|
|
152
152
|
|
|
153
|
+
// TODO@major Overly complicated "patch" is only needed to support the deprecated @disposeOnUnmount
|
|
153
154
|
patch(prototype, "componentWillUnmount", function () {
|
|
154
155
|
if (isUsingStaticRendering()) {
|
|
155
156
|
return
|
|
@@ -207,12 +208,6 @@ function createReactiveRender(originalRender: any) {
|
|
|
207
208
|
|
|
208
209
|
function createReaction(admin: ObserverAdministration) {
|
|
209
210
|
return new Reaction(`${admin.name}.render()`, () => {
|
|
210
|
-
if (admin.isUpdating) {
|
|
211
|
-
// Reaction is suppressed when setting new state/props/context,
|
|
212
|
-
// this is when component is already being updated.
|
|
213
|
-
return
|
|
214
|
-
}
|
|
215
|
-
|
|
216
211
|
if (!admin.mounted) {
|
|
217
212
|
// This is neccessary to avoid react warning about calling forceUpdate on component that isn't mounted yet.
|
|
218
213
|
// This happens when component is abandoned after render - our reaction is already created and reacts to changes.
|
|
@@ -221,14 +216,10 @@ function createReaction(admin: ObserverAdministration) {
|
|
|
221
216
|
}
|
|
222
217
|
|
|
223
218
|
try {
|
|
224
|
-
// forceUpdate sets new `props`, since we made it observable, it would `reportChanged`, causing a loop.
|
|
225
|
-
admin.isUpdating = true
|
|
226
219
|
admin.forceUpdate?.()
|
|
227
220
|
} catch (error) {
|
|
228
221
|
admin.reaction?.dispose()
|
|
229
222
|
admin.reaction = null
|
|
230
|
-
} finally {
|
|
231
|
-
admin.isUpdating = false
|
|
232
223
|
}
|
|
233
224
|
})
|
|
234
225
|
}
|
|
@@ -251,40 +242,23 @@ function observerSCU(nextProps: ClassAttributes<any>, nextState: any): boolean {
|
|
|
251
242
|
}
|
|
252
243
|
|
|
253
244
|
function createObservablePropDescriptor(key: "props" | "state" | "context") {
|
|
254
|
-
const atomKey = `${key}Atom`
|
|
255
245
|
return {
|
|
256
246
|
configurable: true,
|
|
257
247
|
enumerable: true,
|
|
258
248
|
get() {
|
|
259
249
|
const admin = getAdministration(this)
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
250
|
+
const derivation = _getGlobalState().trackingDerivation
|
|
251
|
+
if (derivation && derivation !== admin.reaction) {
|
|
252
|
+
throw new Error(
|
|
253
|
+
`[mobx-react] Cannot read "${admin.name}.${key}" in a reactive context, as it isn't observable.
|
|
254
|
+
Please use component lifecycle method to copy the value into a local observable first.
|
|
255
|
+
See https://github.com/mobxjs/mobx/blob/main/packages/mobx-react/README.md#note-on-using-props-and-state-in-derivations`
|
|
256
|
+
)
|
|
257
|
+
}
|
|
267
258
|
return admin[key]
|
|
268
259
|
},
|
|
269
260
|
set(value) {
|
|
270
|
-
|
|
271
|
-
// forceUpdate issued by reaction sets new props.
|
|
272
|
-
// It sets isUpdating to true to prevent loop.
|
|
273
|
-
if (!admin.isUpdating && !shallowEqual(admin[key], value)) {
|
|
274
|
-
admin[key] = value
|
|
275
|
-
// This notifies all observers including our component,
|
|
276
|
-
// but we don't want to cause `forceUpdate`, because component is already updating,
|
|
277
|
-
// therefore supress component reaction.
|
|
278
|
-
admin.isUpdating = true
|
|
279
|
-
admin[atomKey].reportChanged()
|
|
280
|
-
admin.isUpdating = false
|
|
281
|
-
} else {
|
|
282
|
-
admin[key] = value
|
|
283
|
-
}
|
|
261
|
+
getAdministration(this)[key] = value
|
|
284
262
|
}
|
|
285
263
|
}
|
|
286
264
|
}
|
|
287
|
-
|
|
288
|
-
const observablePropsDescriptor = createObservablePropDescriptor("props")
|
|
289
|
-
const observableStateDescriptor = createObservablePropDescriptor("state")
|
|
290
|
-
const observableContextDescriptor = createObservablePropDescriptor("context")
|