UNPKG

mobx

Version:

Simple, scalable state management.

597 lines (397 loc) 113 kB
# mobx ## 6.1.8 ### Patch Changes - [`ca4914f9`](https://github.com/mobxjs/mobx/commit/ca4914f978aef427e7b2223328fd66b82e522d89) [#2836](https://github.com/mobxjs/mobx/pull/2836) Thanks [@urugator](https://github.com/urugator)! - Fix [#2832](https://github.com/mobxjs/mobx/issues/2832) - annotation cache ignores overrides ## 6.1.7 ### Patch Changes - [`5640aa77`](https://github.com/mobxjs/mobx/commit/5640aa7794420a5fc2f99ac0819de11696d6ba71) [#2799](https://github.com/mobxjs/mobx/pull/2799) Thanks [@urugator](https://github.com/urugator)! - - fix: user provided debug names are not preserved on production - fix: property atom's debug name is dynamic on production - fix: `observable(primitive, options)` ignores `options` - fix: `getDebugName(action)` throws `[MobX] Cannot obtain atom from undefined` - [fix: terser using `unsafe: true`](https://github.com/mobxjs/mobx/issues/2751#issuecomment-778171773) ## 6.1.6 ### Patch Changes - [`9b195b17`](https://github.com/mobxjs/mobx/commit/9b195b17bd661b9c0c4ab3a8ef323e23c2f118e4) [#2780](https://github.com/mobxjs/mobx/pull/2780) Thanks [@iChenLei](https://github.com/iChenLei)! - The overall memory usage of MobX has been reduced in production builds by skipping the generation of debug identifiers. The internal `mapid_` field of Reaction has been removed as part of the change. ## 6.1.5 ### Patch Changes - [`3979bee3`](https://github.com/mobxjs/mobx/commit/3979bee36c82d342050978834197ea15a7ddbbf8) [#2773](https://github.com/mobxjs/mobx/pull/2773) Thanks [@urugator](https://github.com/urugator)! - Decorators optimization * [`7820e5ea`](https://github.com/mobxjs/mobx/commit/7820e5eae0c9dcdfa1e69cf92e0bfa209b2b478b) [#2769](https://github.com/mobxjs/mobx/pull/2769) Thanks [@iChenLei](https://github.com/iChenLei)! - add warn for extending builtins - [`a7c15171`](https://github.com/mobxjs/mobx/commit/a7c1517133915c2891e92a865fe5475627b6b89f) [#2775](https://github.com/mobxjs/mobx/pull/2775) Thanks [@pkit](https://github.com/pkit)! - use globalThis in global detection * [`5d41b646`](https://github.com/mobxjs/mobx/commit/5d41b6462cf609df869a088e353bc485846c88f8) [#2774](https://github.com/mobxjs/mobx/pull/2774) Thanks [@urugator](https://github.com/urugator)! - Fix: `makeAutoObservable` now working properly with symbolic keys Fix: `isComputedProp` and `getAtom` second arg type is incompatible with Symbols ## 6.1.4 ### Patch Changes - [`0677c0e7`](https://github.com/mobxjs/mobx/commit/0677c0e788bc11ceba909bba16b2b009e90a4c97) [#2766](https://github.com/mobxjs/mobx/pull/2766) Thanks [@urugator](https://github.com/urugator)! - Fix: Inherited annotated fields are not assignable ## 6.1.3 ### Patch Changes - [`d2a2a52e`](https://github.com/mobxjs/mobx/commit/d2a2a52e59e1cf5867bf72e49e7f134c7055ac5d) [#2763](https://github.com/mobxjs/mobx/pull/2763) Thanks [@vkrol](https://github.com/vkrol)! - Add `safeDescriptors` to `configure` options type ## 6.1.2 ### Patch Changes - [`ca09f2f5`](https://github.com/mobxjs/mobx/commit/ca09f2f5744f438b0b6572b60e055ca8b59646de) [#2761](https://github.com/mobxjs/mobx/pull/2761) Thanks [@urugator](https://github.com/urugator)! - `configure({ safeDescriptors: false })` now forces all props of observable objects to be writable and configurable ## 6.1.1 ### Patch Changes - [`39eca50d`](https://github.com/mobxjs/mobx/commit/39eca50de3936807037cb1205bbab29a3e328bc0) [#2757](https://github.com/mobxjs/mobx/pull/2757) Thanks [@urugator](https://github.com/urugator)! - Fix error stringification on minified build Fix `isObservableProp` not supporting `Symbols` Fix `makeAutoObservable` not ignoring `inferredAnnotationsSymbol` ## 6.1.0 This release fixes a plethora of bugs related to sub-classing and reflecting / iterating on observable objects. The behavior of MobX is in many edge cases much more explicitly defined now. A new annotation was introduced: `@override` / `override` to support re-defining actions and computed values(!) on sub classses. For idiomatic MobX usage this release should have little impact, but if you are using a lot of sub-classing, reflection APIs or direct object manipulations like `defineProperty`, this release might introduce previously unseen errors for cases that silently failed before, or even worked successfully even though the correct behavior wasn't specified earlier. If you are migrating from MobX 4/5 we strongly recommend to go to 6.1 in one go, and skip 6.0.\*, as some buggy behavior compared to the previous majors has been corrected. As always, our libraries come as-is and are maintained by volunteers. Upgrades are at own risk and voluntary. Bug reports require a minimal reproductions and a correctly filled out issue template. Support the ongoing maintenance at: https://opencollective.com/mobx ### Minor Changes [`28f8a11d`](https://github.com/mobxjs/mobx/commit/28f8a11d8b94f1aca2eec4ae9c5f45c5ea2f4362) [#2641](https://github.com/mobxjs/mobx/pull/2641) Thanks [@urugator](https://github.com/urugator)! - `action`, `computed`, `flow` defined on prototype can be overriden by subclass via `override` annotation/decorator. Previously broken. - Overriding anything defined on instance itself (`this`) is not supported and should throw. Previously partially possible or broken. - Attempt to re-annotate property always throws. Previously mostly undefined outcome. - All annotated and non-observable props (action/flow) are non-writable. Previously writable. - All annotated props of non-plain object are non-configurable. Previously configurable. - Observable object should now work more reliably in various (edge) cases. - Proxied objects now support `Object.defineProperty`. Previously unsupported/broken. - `extendObservable/makeObservable/defineProperty` notifies observers/listeners/interceptors about added props. Previously inconsistent. - `keys/values/entries` works like `Object.keys/values/entries`. Previously included only observables. - `has` works like `in`. Previously reported `true` only for existing own observable props. - `set` no longer transforms existing non-observable prop to observable prop, but simply sets the value. - `remove/delete` works with non-observable and computed props. Previously unsupported/broken. - Passing `options` to `observable/extendObservable/makeObservable` throws if the object is already observable . Previously passed options were mostly ignored. - `autoBind` option is now sticky - same as `deep` and `name` option. - `observable/extendObservable` now also picks non-enumerable keys (same as `make[Auto]Observable`). - Removed deprecated `action.bound("name")` - Proxied objects should be compatible with `Reflect` API. Previously throwing instead of returning booleans. ## 6.0.5 ### Patch Changes - [`6b304232`](https://github.com/mobxjs/mobx/commit/6b30423266e5418a3f20389d0bd0eae31f3384d2) [#2644](https://github.com/mobxjs/mobx/pull/2644) Thanks [@rokoroku](https://github.com/rokoroku)! - Fix broken error reference in errors.ts * [`83b84fd3`](https://github.com/mobxjs/mobx/commit/83b84fd354f2253fdd8ea556e217a92fc2633c00) [#2740](https://github.com/mobxjs/mobx/pull/2740) Thanks [@iChenLei](https://github.com/iChenLei)! - Infer optional / promise `action` args type correctly - [`65c7b73b`](https://github.com/mobxjs/mobx/commit/65c7b73b7f0b1a69a1a2786b5f484419d129d10b) [#2717](https://github.com/mobxjs/mobx/pull/2717) Thanks [@ahoisl](https://github.com/ahoisl)! - The TypeScript type `CreateObservableOptions` is now exported. * [`989390d4`](https://github.com/mobxjs/mobx/commit/989390d46bbe9941b61ac6c6d1292f96445e7cc3) [#2594](https://github.com/mobxjs/mobx/pull/2594) Thanks [@urugator](https://github.com/urugator)! - Fixed [#2579](https://github.com/mobxjs/mobx/issues/2579) - `observable` does not ignore class instances - [`dea1cf18`](https://github.com/mobxjs/mobx/commit/dea1cf189b0f43929f4f626229d34a80bd10212e) [#2726](https://github.com/mobxjs/mobx/pull/2726) Thanks [@mweststrate](https://github.com/mweststrate)! - fix: `onBecomeObserved` was not triggered correctly for computed dependencies of computeds. Fixes #2686, #2667 * [`592e6e99`](https://github.com/mobxjs/mobx/commit/592e6e996c2d5264e162cfb0921a071c1d815c92) [#2743](https://github.com/mobxjs/mobx/pull/2743) Thanks [@vkrol](https://github.com/vkrol)! - Remove `sideEffects` section in `mobx-react-lite` `package.json` > 🚨🚨🚨 If you are upgrading from V4/V5, please follow [the migration guide](https://mobx.js.org/migrating-from-4-or-5.html). ## 6.0.4 ### Patch Changes - [`79a09f49`](https://github.com/mobxjs/mobx/commit/79a09f49a9f2baddbab8d89e9a7ac07cffadf624) [#2615](https://github.com/mobxjs/mobx/pull/2615) Thanks [@urugator](https://github.com/urugator)! - Fix [#2614](https://github.com/mobxjs/mobx/issues/2614) - `makeObservable` does not respect `options.name` ## 6.0.3 ### Patch Changes - [`d0e6778d`](https://github.com/mobxjs/mobx/commit/d0e6778de73f6dfad61283c04103049732b2aea2) - Create ESM bundles with NODE_ENV correctly replaced so it can be used in browser (#2564) ## 6.0.2 ### Patch Changes - [`b5d64d19`](https://github.com/mobxjs/mobx/commit/b5d64d1965ecd9a593886279ddaf96eda61c4a77) [#2548](https://github.com/mobxjs/mobx/pull/2548) Thanks [@urugator](https://github.com/urugator)! - Fixed [2542](https://github.com/mobxjs/mobx/issues/2542), makeAutoObservable not respecting deep option [@urugator](https://github.com/urugator) * [`f4c22925`](https://github.com/mobxjs/mobx/commit/f4c229259a72f0497d3f9b6a05af9d9c4280d8b1) [#2582](https://github.com/mobxjs/mobx/pull/2582) Thanks [@tomenden](https://github.com/tomenden)! - Support running in a web-worker ## 6.0.1 - Fixed issue in TS typings of `makeObservable` in combination with a member named `toString()` ## 6.0.0 ### New features - [`makeObservable(target, annotations)`](./docs/observable-state.md#makeobservable) is now the recommended way to make objects with a fixed shape observable, such as classes. - [`makeAutoObservable(target)`](./docs/observable-state.md#makeautoobservable) will automatically determine the annotations used by `makeObservable`. Methods will be marked as 'autoAction', so that they can be used both from a computed value or as standalone method. - MobX 6 can be used in both modern environments, and environments that don't support Proxy. So both MobX 4 and 5 users can upgrade to 6. See [proxy support](./docs/configuration.md#proxy-support) for more details. - `observable.array` now supports `{ proxy: false }` as option. - `reaction`'s effect function now receives the previous value seen by the reaction as second argument. - `flow` can now be used as annotation as well. You might need `flowResult` in case you use TypeScript to extract the correct result type. [details](./docs/actions.md#using-flow-instead-of-async--await-). ### Breaking changes #### Changes that might affect you - The `decorate` API has been removed, and needs to be replaced by `makeObservable` in the constructor of the targeted class. It accepts the same arguments. The `mobx-undecorate` can transform this automatically. - When using `extendObservable` / `observable`, fields that contained functions used to be turned into observables. This is no longer the case, they will be converted into `autoActions`. - [Strict mode](./docs/configuration.md#enforceactions) for actions is now enabled by default in `observed` mode. - `toJS` no longer takes any options. It no longer converts Maps and Sets to plain data structures. Generic, flexible serialization of data structures is out of scope for the MobX project, and writing custom serialization methods is a much more scalable approach to serialization (tip: leverage `computed`s to define how class instances should be serialized). - The methods `intercept` and `observe` are no longer exposed on observable arrays, maps and boxed observables. Import them as utility from mobx instead: `import { observe, intercept } from "mobx"`, and pass the collection as first argument: `observer(collection, callback)`. Note that we still recommend to avoid these APIs. - `observableMap.toPOJO()`, `observableMap.toJS()` have been dropped. Use `new Map(observableMap)` instead if you want to convert an observable map to a plain Map shallowly. - `observableMap.toJSON()` now returns an entries array rather than a new Map, to better support serialization. - `observableSet.toJS()` has been dropped. Use `new Set(observableSet)` instead if you want to convert an observable Set to a plain Set shallowly. - `observableSet.toJSON()` now returns an array rather than a new Set, to better support serialization. - Sorting or reversing an observableArray in a derivation (without slicing first) will now throw rather than warn. In contrast, it is now allowed to sort or reverse observable arrays in-place, as long as it happens in an action. - `isArrayLike` is no longer exposed as utility. Use `Array.isArray(x) || isObservableArray(x)` instead. #### Obscure things that don't work anymore, but that probably won't affect you - It is no longer possible to re-decorate a field (through either `@observable` or `makeObservable`) that is already declared in a super class. - `runInAction` no longer supports passing a name as first argument. Name the original function or use `action(name, fn)()` if you care about the debug name. - `computed(getterFn, setterFn)` no longer accepts a setter function as a second argument. Use the `set` option instead: `computed(getterFn, { set: setterFn })`. - In observable arrays, for `findIndex` / `find` method, the `offset` argument (the third one) is no longer supported, to be consistent with ES arrays. - The option `computedConfigurable` of `configure` is no longer supported as it is now the default. - `observableArray.toJS()` has been removed, use `observableArray.slice()` instead, which does the same. - Killed support for the `IGNORE_MOBX_MINIFY_WARNING` environment flag. - `_allowStateChangesInComputation(fn)` is no longer needed, use `runInAction(fn)` instead. - In `computed`, the `when` predicate (first arg), and `reaction` predicate (first arg) it is now forbidden to directly change state. State changes should be done in their effect functions, or otherwise at least wrapped in `runInAction` (only the state change, not the observables you want to track!). Note that this is still an anti-pattern. - The `observableArray.get()` and `observableArray.set()` methods are no longer supported. - The `IObservableObject` interface is no longer exported from MobX. - The second argument to the `reaction` effect function, the disposer object, is now passed in as third argument. The second argument is now the previous value seen by the reaction. - `onBecomeObserved` / `onBecomeUnobserved` will now only trigger for observables that are actually used by a reaction (see [#2309](https://github.com/mobxjs/mobx/issues/2309) for background). ### Fixes - [#2326](https://github.com/mobxjs/mobx/issues/2326): Incorrect `this` for array callbacks such as in `array.forEach` - [#2379](https://github.com/mobxjs/mobx/issues/2379): Fixed issue with `array.concat` - [#2309](https://github.com/mobxjs/mobx/issues/2309): Fixed several inconsistencies between keepAlive'd computed values and `on(un)BecomeObserved` - Fixed several inconsistencies when `on(un)BecomeObserved` was triggered for observables changed in actions without having an observer ## 5.15.7 / 4.15.7 - Fixed [2438](https://github.com/mobxjs/mobx/issues/2438), factory types caused eslint warnings, by [@amareis](https://github.com/Amareis) through [2439](https://github.com/mobxjs/mobx/pull/2439) - Fixed [2432](https://github.com/mobxjs/mobx/issues/2423), array.reduce without initial value by [@urugator](https://github.com/urugator) ## 5.15.6 / 4.15.6 - Fixed [2423](https://github.com/mobxjs/mobx/issues/2423), array methods not dehancing by [@urugator](https://github.com/urugator) - Fixed [2424](https://github.com/mobxjs/mobx/issues/2424) Map / Set instantiation triggering a strict warning, through [#2425](https://github.com/mobxjs/mobx/pull/2425) by [@moonball](https://github.com/moonball) ## 5.15.5 / 4.15.5 - Fixed ObservableSet.prototype.forEach not being reactive in 4.x [#2341](https://github.com/mobxjs/mobx/pull/2341) by [@melnikov-s](https://github.com/melnikov-s) - Add error when computed value declared for unspecified getter [#1867](https://github.com/mobxjs/mobx/issues/1867) by [@berrunder](https://github.com/berrunder) - Fixed [#2326](https://github.com/mobxjs/mobx/issues/2326) correct array is passed to callbacks by [@urugator](https://github.com/urugator) - Fixed [#2278](https://github.com/mobxjs/mobx/issues/2278), `map.delete` should respect strict mode, by [@urugator](https://github.com/urugator) - Fixed [#2253](https://github.com/mobxjs/mobx/issues/2253), [#1980](https://github.com/mobxjs/mobx/issues/1980), map key order not always preserved by [@urugator](https://github.com/urugator) - Fixed [#2412](https://github.com/mobxjs/mobx/issues/2412), non-enumerable getters not being picked up by `extendObservable` by [@urugator](https://github.com/urugator) - Several performance improvements - Dropped `browser` fields from `package.json` ## 5.15.4 / 4.15.4 - Fix process.env replacement in build [#2267](https://github.com/mobxjs/mobx/pull/2267) by [@fredyc](https://github.com/fredyc) ## 5.15.3 / 4.15.3 - Define action name to be as the function name [#2262](https://github.com/mobxjs/mobx/pull/2262) by [@nadavkaner](https://github.com/nadavkaner) ## 5.15.2 / 4.15.2 - Fixed [#2230](https://github.com/mobxjs/mobx/issue/2230) computedvalue: throw error object instead of string when options is empty [#2243](https://github.com/mobxjs/mobx/pull/2243) by [@ramkumarvenkat](https://github.com/ramkumarvenkat) - supports ES6 Sets and Maps in shallow comparer. [#2238](https://github.com/mobxjs/mobx/pull/2238) by [@hearnden](https://github.com/hearnden) - `extendObservable`: can be used existing properties again. Fixes [#2250](https://github.com/mobxjs/mobx/issue/2250) through [#2252](https://github.com/mobxjs/mobx/pull/2252) by [@davefeucht](https://github.com/davefeucht) ## 5.15.1 / 4.15.1 - Make initial values of observable set accept readonly array [#2202](https://github.com/mobxjs/mobx/pull/2202) - Expose `_allowStateReadsStart` & `_allowStateReadsEnd`. This is low level stuff you shouldn't need that's mostly useful for library creators. [#2233](https://github.com/mobxjs/mobx/pull/2233) - Fixed an issue with `observableRequiresReaction` and updating observable during reaction [#2195](https://github.com/mobxjs/mobx/pull/2196) - Improved type inference for `action` [#2213](https://github.com/mobxjs/mobx/pull/2213) ([see detailed explanation](https://github.com/mobxjs/mobx/pull/2218#discussion_r349889440)) ## 5.15.0 **The minimum required TypeScript version is now 3.6** - Fixed flow typings with Typescript v3.6. This means that version of Typescript is required when using flows. - Cancelled flows now reject with a `FlowCancellationError` instance whose error message is the same as in previous versions (`"FLOW_CANCELLED"`) so this is not breaking. [#2172](https://github.com/mobxjs/mobx/pull/2172) by [@vonovak](https://github.com/vonovak) - Fix running mobx in web worker [#2184](https://github.com/mobxjs/mobx/pull/2184/files) by [@shahata](https://github.com/shahata) - Fixed flow typings for Facebook's Flow. A new `CancellablePromise` Flow type is exported. [#2164](https://github.com/mobxjs/mobx/pull/2164) by [@vonovak](https://github.com/vonovak) - Added support for symbol keys on observable properties (MobX 5 only). [#2175](https://github.com/mobxjs/mobx/pull/2175) by [@StephenHaney](https://github.com/StephenHaney) ## 5.14.2 - Fixed installation issue trying to run `postinstall` hook for a website [#2165](https://github.com/mobxjs/mobx/issues/2165). ## 5.14.1 / 4.14.1 - Fixed a possible issue with action stack errors and multiple mobx versions installed at the same time [#2135](https://github.com/mobxjs/mobx/issues/2135). - Added `comparer.shallow` for shallow object/array comparisons [#1561](https://github.com/mobxjs/mobx/issues/1561). - Fixed disposing an interception within an interception throwing an error [#1950](https://github.com/mobxjs/mobx/issues/1950). ## 5.14.0 / 4.14.0 - Added experimental `reactionRequiresObservable` & `observableRequiresReaction` config [#2079](https://github.com/mobxjs/mobx/pull/2079), [Docs](https://github.com/mobxjs/mobx/pull/2082) - Added experimental `requiresObservable` config to `reaction`, `autorun` & `when` options [#2079](https://github.com/mobxjs/mobx/pull/2079), [Docs](https://github.com/mobxjs/mobx/pull/2082) ## 5.13.1 / 4.13.1 - Don't use `global` and `self` keywords unless defined. Fixes [#2070](https://github.com/mobxjs/mobx/issues/2070). - onBecome(Un)Observed didn't trigger when using number as key of observable map. Fixes [#2067](https://github.com/mobxjs/mobx/issues/2067). - Exposed `_startAction` and `_endAction` to be able to start and action and finish it without needing a code block. This is low level stuff you shouldn't need that's mostly useful for library creators. ## 5.13.0 / 4.13.0 - Fixed potential memory leak in observable maps, when non-primitive values are used as keys. Fixes [#2031](https://github.com/mobxjs/mobx/issues/2031) through [#2032](https://github.com/mobxjs/mobx/pull/2032). - Added support to store additional non-observable(!) fields (string or symbol based) on array, to better reflect behavior of MobX 4. Fixes [#2044](https://github.com/mobxjs/mobx/issues/2044) through [#2046](https://github.com/mobxjs/mobx/pull/2046) ## 5.11.0 / 4.12.0 - Added `computedConfigurable` config [#2011](https://github.com/mobxjs/mobx/pull/2011), [#2013](https://github.com/mobxjs/mobx/pull/2014) ## 4.11.0 **BREAKING CHANGE** Reverted the support of Symbols in general in MobX 4, as it gives to many potential build errors and increases the system requirements for MobX 4 (which was an oversight in 4.10.0). Apologies for the breaking change (lack of new major version numbers). If lock files are properly used however, no harm should be caused by this change. - Reverted `Symbol` support in observable maps and objects. Reverts [#1944](https://github.com/mobxjs/mobx/pull/1944) through [#1988](https://github.com/mobxjs/mobx/pull/1988). Fixes [#1986](https://github.com/mobxjs/mobx/issues/1986), [#1987](https://github.com/mobxjs/mobx/issues/1987) ## 5.10.1 - Fixed a recent regression where array update events would send undefined as `change.object` through [#1985](https://github.com/mobxjs/mobx/pull/1985) by [xaviergonz](https://github.com/xaviergonz) ## 5.10.0 / 4.10.0 - Added support for symbol named properties in maps and objects. Fixes [#1809](https://github.com/mobxjs/mobx/issues/1809) and [#1925](https://github.com/mobxjs/mobx/issues/1925) through [#1944](https://github.com/mobxjs/mobx/pull/1944) by [@loklaan](https://github.com/loklaan) - Added `set` support for `observable.set`, see [#1945](https://github.com/mobxjs/mobx/pull/1945) by [xaviergonz](https://github.com/xaviergonz) - Fixed events for arrays using the wrong object, [#1964](https://github.com/mobxjs/mobx/pull/1964) by [xaviergonz](https://github.com/xaviergonz) - Improved flow typings [#1960](https://github.com/mobxjs/mobx/pull/1960) by [@tbezman](https://github.com/tbezman) - Updated tooling, [#1949](https://github.com/mobxjs/mobx/pull/1949) and [#1931](https://github.com/mobxjs/mobx/pull/1931) by [xaviergonz](https://github.com/xaviergonz) ## 5.9.4 / 4.9.4 - Allow symbol keys in `ObservableMap`, see [#1930](https://github.com/mobxjs/mobx/pull/1930) by [pimterry](https://github.com/pimterry) - Fixed type definitions of `toStringTag` for Maps and Sets, see [#1929](https://github.com/mobxjs/mobx/pull/1929) by [lennerd](https://github.com/lennerd) ## 4.9.3 - Fixed `observable.set` compatibility with IE 11, see [#1917](https://github.com/mobxjs/mobx/pull/1917) by [kalmi](https://github.com/kalmi) ## 4.9.2 - Fixed regression [#1878](https://github.com/mobxjs/mobx/issues/1878), accidental use of `Symbol` breaking Internet Explorer / React Native compatibility. ## 4.9.1 - Fixed regression in `toJS`: observable maps were not properly serialized. Fixes [#1875](https://github.com/mobxjs/mobx/issues/1875) ## 5.9.0 / 4.9.0 **Features** - Introduced support for observable sets! Through [#1592](https://github.com/mobxjs/mobx/pull/1592) by [@newraina](https://github.com/newraina) - `observable.box` now accepts an `equals` option, to be able to pass a custom comparision function. Through [#1862](https://github.com/mobxjs/mobx/pull/1862), [#1874](https://github.com/mobxjs/mobx/pull/1874) by [@fi3ework](https://github.com/fi3ework). Fixes [#1580](https://github.com/mobxjs/mobx/issues/1580) - Improved logging of reactions; if an action throws an exception, errors in reactions that react to that are only logged as warnings. Fixes [#1836](https://github.com/mobxjs/mobx/issues/1836) **Fixes** - Improved typings for `flow`, see [#1827](https://github.com/mobxjs/mobx/pull/1827) by [@xaviergonz](https://github.com/xaviergonz) - Don't allow subclassing map, fixes [#1858](https://github.com/mobxjs/mobx/issues/1858) - Fixed `trace(true)` not being able to handle multi-line comments in traced function. Fixes [#1850](https://github.com/mobxjs/mobx/issues/1850) - `@computed` now introduces non-configurable properties, to fail fast on incorrect inheritance or property deletion. Fixes [#1867](https://github.com/mobxjs/mobx/issues/1867) - The options `enforceActions` and `isolateGlobalState` now work correctly when used together. Fixes [#1869](https://github.com/mobxjs/mobx/issues/1869) ## 5.8.0 / 4.8.0 - MobX now requires TypeScript 3 (this was already the case in 5.7.0, but in this version the difference is actually noticeable in the typings). - Fixed array dehancer sometimes skipping. Fixes [#1839](https://github.com/mobxjs/mobx/issues/1839) through [#1841](https://github.com/mobxjs/mobx/pull/1841) by [k-g-a](https://github.com/k-g-a) - Fixed issue where webpack 4 wouldn't use the ESM module [#1834](https://github.com/mobxjs/mobx/pull/1834) by [mrtnbroder](https://github.com/mrtnbroder) - Improved type inference for `flow` in TypeScript 3. Fixes [#1816](https://github.com/mobxjs/mobx/issue/1816) through [#1825](https://github.com/mobxjs/mobx/pull/1825) by [ismailhabib](https://github.com/ismailhabib) - Introduced support for global environment variable `IGNORE_MOBX_MINIFIY_WARNING=true` to skip the built-in minification warning. See [#1835](https://github.com/mobxjs/mobx/pull/1835) by [fi3ework](https://github.com/fi3ework) - Fixed onBecome(Un)Observed dispoer cleanup. Fixes [#1537](https://github.com/mobxjs/mobx/issues/1537) through [#1833](https://github.com/mobxjs/mobx/pull/1833) by [fi3ework](https://github.com/fi3ework) ## 5.7.1 / 4.7.1 - Fixed [#1839](https://github.com/mobxjs/mobx/issues/1839), ObservableArrayAdministration.dehanceValues does not dehance last value. ## 5.7.0 / 4.7.0 - Upgraded typings to TypeScript 3 - Fixed [#1742](https://github.com/mobxjs/mobx/issues/1742), change detection fails when multiple mobx instances were active. - Fixed [#1624](https://github.com/mobxjs/mobx/issues/1624), use built-in flow types for iterators - Fixed [#1777](https://github.com/mobxjs/mobx/issues/1777) through [#1826](https://github.com/mobxjs/mobx/pull/1826), stack overflow exception, in development mode, when using `@computed` on a React component. The MobX 5 behavior here has been reverted to the MobX 4 behavior. ## 5.6.0 / 4.6.0 - `keepAlive` has become smarter and won't recomputed computed values that are kept alive, as long as they aren't read. Implements [#1534](https://github.com/mobxjs/mobx/issues/1534) - Fixed [#1796](https://github.com/mobxjs/mobx/issues/1796), undeleting a property that had an initial value of `undefined` was undetected - Improved Flow typings, see [#1794](https://github.com/mobxjs/mobx/pull/1794) and [#1786](https://github.com/mobxjs/mobx/pull/1786) ## 5.5.2 / 4.5.2 - Fixed bug in `toJS` not handling `null` values correctly. Fixes [#1557](https://github.com/mobxjs/mobx/issues/1557) through [#1783](https://github.com/mobxjs/mobx/pull/1783) by [@wangyiz4262](https://github.com/wangyiz4262) ## 5.5.1 / 4.5.1 - `toJS` now has a `recurseEverything` everything option, that even detects and converts observable objects that are "behind" non-observable objects. See [#1699](https://github.com/mobxjs/mobx/pull/1699) by [wangyiz4262](https://github.com/wangyiz4262) - Added flow typings form `comparer`, see [#1751](https://github.com/mobxjs/mobx/pull/1752) by [pdong](https://github.com/pdong) - Update flow typings for configuration options, [#1772](https://github.com/mobxjs/mobx/pull/1772) by [alexandersorokin](https://github.com/alexandersorokin) ## 5.5.0 / 4.5.0 (Minor version of `5` was bumped significantly to make the number better correlate together :-)) - Fixed [#1740](https://github.com/mobxjs/mobx/issues/1740): combining decorators and `extendObservable` in a class constructor caused errors to be thrown - Fixed [#1739](https://github.com/mobxjs/mobx/issues/1740): - Proxies: `delete`-ing a property was not always picked up by the reactivity system - Non-proxies: `remove()`-ing a property was not always picked up by the `has()` and `get()` utilities - `has` now returns `true` for computed fields - `get` now returns a value for computed fields - Introduced `_allowStateChangeInsideComputed`. Don't use it :-). - MobX is now transpiled using babel 7 ## 5.1.2 / 4.4.2 - Fixed [#1650](https://github.com/mobxjs/mobx/issues/1650), decorating fields with the name `toString` does not behave correctly. ## 5.1.1 / 4.4.1 - Improved typings of `decorate`, see [#1711](https://github.com/mobxjs/mobx/pull/1711) by [makepost](https://github.com/makepost) ## 5.1.0 / 4.4.0 - Improved handling of multiple MobX instances. MobX will no longer complain about being loaded multiple times (one should still prevent it though, to prevent blowing up bundle size!), but merge internal state by default. If multiple MobX versions need to be loaded, call `configure({ isolateGlobalState: true })`. Note that this means that observables from the different MobX instances won't cooperate. Fixes [#1681](https://github.com/mobxjs/mobx/issues/1681), [#1082](https://github.com/mobxjs/mobx/issues/1082) - `enforceActions` options now supports the values: `"never"`, `"observed"` and `"always"` to make the behavior more clear. Fixes [#1680](https://github.com/mobxjs/mobx/issues/1680), [#1473](https://github.com/mobxjs/mobx/issues/1473) ## 5.0.5 - Fixed [#1667](https://github.com/mobxjs/mobx/issues/1667): creating a large array could result in undefined items (MobX 4.\* was not affected) ## 4.3.2 / 5.0.4 - Fixed [#1685](https://github.com/mobxjs/mobx/issues/1685): expose `IAutorunOptions` - `decorate` now can apply multiple decorators, by accepting an array and applying them right to left: `decorate(Todo, { title: [serializable(primitive), persist('object'), observable] })`. By [@ramybenaroya](https://github.com/ramybenaroya) through [#1691](https://github.com/mobxjs/mobx/pull/1691) and [#1686](https://github.com/mobxjs/mobx/pull/1686) - Improved typings of `flow` so that it accepts async generators. By [@dannsam](https://github.com/dannsam) through [#1656](https://github.com/mobxjs/mobx/pull/1656) and [#1655](https://github.com/mobxjs/mobx/pull/1655) - `keys()` now also supports arrays. Fixes [#1600](https://github.com/mobxjs/mobx/pull/1600) through [#1601](https://github.com/mobxjs/mobx/pull/1601) by [@nunocastromartins](https://github.com/nunocastromartins) ## 5.0.3 - Fixed issue where it was no longer possible to define custom properties on observable arrays ## 5.0.2 - Fixed issue where iterators where not compiled to ES5, breaking the ES5 based builds. ## 5.0.1 (Unpublished) - Fixed regression bug: `ObservableMap.size` was no longer observable. Fixes [#1583](https://github.com/mobxjs/mobx/issues/1583) - Downgraded lib export from ES6 to ES5. To many build tools still trip over ES6. Fixes [#1584](https://github.com/mobxjs/mobx/issues/1584). A modern build is available through `import ... from "mobx/lib/mobx.es6"` (or setup an alias in your build system) - Added support for mobx-react-devtools ## 5.0.0 [Release blogpost](https://medium.com/p/4852bce05572/) ### Proxy support! MobX 5 is the first MobX version fully leveraging Proxies. This has two big advantages 1. MobX can now detect the addition of properties on plain observable objects, so it is now possible to use plain observable objects as dynamic collections. 2. Observable arrays are now recognized as arrays by all third party libraries, which will avoid the need to slice them. ### The system requirements to run MobX has been upped - MobX 5 can only be used on environments that support `Proxies`. See the [browser support](https://github.com/mobxjs/mobx#browser-support) for details. - Since MobX no longer runs on older browsers, the compilation target has been upgraded to ES2015 syntax supporting browsers. This means that MobX is not loadable on older browsers without down compilation to ES5. - If for whatever reason your project cannot meet this requirements, please stick to MobX 4. It will be actively maintained. All current features of MobX 5 are expressable in MobX 4 as well, but it means that for example to use dynamic objects some [additional APIs](https://mobx.js.org/refguide/object-api.html) are needed. - The performance footprint of MobX 5 should be pretty similar to MobX 4. In our performance tests we saw some minor improvements in memory footprint, but overall it should be pretty comparable. ### Breaking changes - The required runtime needs to support the non-polyfillable `Proxy` API. - The minimum runtime target is now ES2015, not ES5 - `spy` has become a no-op in production builds - All earlier deprecated APIs are dropped. Make sure to not have any deprecation warnings before upgrading. - `array.move` and `array.peek` are removed from the API - Dropped the third argument to `array.find` and `array.findIndex` since they were not standardized in ES. - `.$mobx` property has been dropped from all observables and replaced by a Symbol. Instead of using `x.$mobx.name`, use `import { $mobx } from "mobx"; x[$mobx].name` etc. - In some cases, the order in which autoruns are fired could have changed due to some internal optimizations (note that MobX never had a guarantee about the order in which autoruns fired!) ### New features - It is possible to pass the `proxy: false` argument to `observable.object` to disable proxying (theoretically slightly faster, but removes no dynamic key addition) ### Known Issues - Observable objects can no longer be frozen (otherwise they would become un-observable😎). If you are actually trying to do so MobX will now throw an exception like: `[mobx] Dynamic observable objects cannot be frozen]`. A place where that might happen unexpectedly is when passing an observable object as `style` property to a React component. Like `<span style={someObservableObject} />`, since React will freeze all style objects. The work-around is to simply pass a fresh, non-observable object for styling like: `<span style={{...someObservableObject}} />`. - ~~If you are using `mobx` with `mobx-react`, and you are upgrading `mobx-react` to the MobX 5 compatible version (`mobx-react@5.2.0`) you will notice that `this.props` or `this.state` are not yet observable in the `constructor` or `componentWillMount`. This is for forward compatibility with React 16.3 where `componentWillMount` has been deprecated. In most cases using `componentDidMount` instead will suffice, especially when the goal is to setup reactions. For more info see [#478](https://github.com/mobxjs/mobx-react/issues/478).~~ Fixed in mobx-react 5.2.1. But note that you should still migrate away from `componentWillMount`😎. - Jest `toEqual` might throw an error `allKeys[x].match is not a function` when trying to equal observable arrays. This is a bug in Jest [report](https://github.com/facebook/jest/issues/6398). The simple work around for now is to slice (or `toJS` if the problem is recursive) the array first. - Jest `toEqual` matcher might no longer correctly equal your class instances, complaining about differences in the MobX adminstration. This is due to a bug with the processing of symbols: [report](https://github.com/facebook/jest/issues/6392). For now you might want to use a custom matcher if you are directly equalling observable objects. As a work around `toJS(object)` could be used before diffing. _Note June 7th, 2018:_ Both issues are already in Jest master and should be released soon. ### Migration guide - Make sure to not use any API that produces deprecation warnings in MobX 4. Beyond that MobX 5 should pretty well as drop-in replacement of MobX 4. - You _could_ perform the following clean ups: - Don't `slice()` arrays when passing them to external libraries. (Note you still shouldn't pass observable data structures to non-`observer` React components, which is an orthogonal concept) - You could replace observable maps with observable objects if you are only using string-based keys. - Don't call the `reverse` or `sort` operations directly on observableArray's anymore, as it's behavior slightly differed from the built-in implementations of those methods. Instead use `observableArray.slice().sort()` to perform the sort on a copy. This gives no additional performance overhead compared to MobX 4. (The reason behind this is that built-in `sort` updates the array in place, but the observable array implementation always performed the sort on a defensive copy, and this change makes that explicit). - you may remove usages of `isArrayLike()` since `Array.isArray()` will now return true for observable arrays ### API's that have been dropped - The `arrayBuffer` setting is no longer supported by `configure` (it has become irrelevant) - `observable.shallowBox`, `observable.shallowArray`, `observable.shallowMap`, `observable.shallowObject`, `extendShallowObservable` api's have been removed. Instead, pass `{ deep: false }` to their non-shallow counter parts. - `observableArray.peek`, `observableArray.move` ## 4.3.1 - Fixed [#1534](Fixes https://github.com/mobxjs/mobx/issues/1534): @computed({keepAlive: true}) no long calculates before being accessed. - Added the `$mobx` export symbol for MobX 5 forward compatibity ## 4.3.0 - Introduced the `entries(observable)` API, by @samjacobclift through [#1536](https://github.com/mobxjs/mobx/pull/1536) - Fixed [#1535](https://github.com/mobxjs/mobx/issues/1535): Change in nested computed value was not propagated if read outside action context when there is a pending reaction. For more details see the exact test case. - Illegal property access through prototypes is now a warning instead of an error. Fixes [#1506](https://github.com/mobxjs/mobx/issues/1506). By @AmazingTurtle through [#1529](https://github.com/mobxjs/mobx/pull/1529) - Fixed issue where providing a custom setter to `@computed({ set: ... })` wasn't picked up - Fixed #1545: Actions properties where not re-assignable when using TypeScript - Illegal Access checks are now a warning instead of an error. Fix ## 4.2.1 - Fixed flow typings for `mobx.configure` [#1521](https://github.com/mobxjs/mobx/pull/1521) by @andrew--r - Improved typings for `mobx.flow`, fixes [#1527](https://github.com/mobxjs/mobx/issues/1527) - Throw error when using `@observable` in combination with a getter. [#1511](https://github.com/mobxjs/mobx/pull/1511) by @quanganhtran - `toJS` now uses Map internally, for faster detection of cycles. [#1517](https://github.com/mobxjs/mobx/pull/1517) by @loatheb - Fixed [#1512](https://github.com/mobxjs/mobx/issues/1512): `observe` hooks not being triggered when using `mobx.set`, Fixed in [#1514](https://github.com/mobxjs/mobx/pull/1514) by @quanganhtran - Several minor improvements, additional tests and doc improvements. ## 4.2.0 - Introduced `configure({ enforceActions: "strict" })`, which is more strict then `enforceActions: true`, as it will also throw on non-observed changes to observables. See also [#1473](https://github.com/mobxjs/mobx/issues/1473) - Fixed [#1480](https://github.com/mobxjs/mobx/issues/1480): Exceptions in the effect handler of `reaction` where not properly picked up by the global reaction system - Fixed a bug where computed values updated their cached value, even when the comparer considered the new value equal to the previous one. Thanks @kuitos for finding this and fixing it! [#1499](https://github.com/mobxjs/mobx/pull/1499) - Undeprecated `ObservableMap`, fixes [#1496](https://github.com/mobxjs/mobx/issues/1496) - Observable arrays now support `Symbol.toStringTag` (if available / polyfilled). This allows libraries like Ramda to detect automatically that observable arrays are arrays. Fixes [#1490](https://github.com/mobxjs/mobx/issues/1490). Note that `Array.isArray` will keep returning false for the entire MobX 4 range. - Actions are now always `configurable` and `writable`, like in MobX 3. Fixes [#1477](https://github.com/mobxjs/mobx/issues/1477) - Merged several improvements to the flow typings. [#1501](https://github.com/mobxjs/mobx/pull/1501) by @quanganhtran - Fixed several accidental usages of the global `fail`, by @mtaran-google through [#1483](https://github.com/mobxjs/mobx/pull/1483) and [#1482](https://github.com/mobxjs/mobx/pull/1482) ## 4.1.1 - Import `default` from MobX will no longer throw, but only warn instead. This fixes some issues with tools that reflect on the `default` export of a module - Disposing a spy listener inside a spy handler no longer causes an exception. Fixes [#1459](https://github.com/mobxjs/mobx/issues/1459) through [#1460](https://github.com/mobxjs/mobx/pull/1460) by [farwayer](https://github.com/farwayer) - Added a missing `runInAction` overload in the flow typings. [#1451](https://github.com/mobxjs/mobx/pull/1451) by [AMilassin](https://github.com/mobxjs/mobx/issues?q=is%3Apr+author%3AAMilassin) - Improved the typings of `decorate`. See [#1450](https://github.com/mobxjs/mobx/pull/1450) by [makepost](https://github.com/mobxjs/mobx/issues?q=is%3Apr+author%3Amakepost) ## 4.1.0 - Introduced `keepAlive` as option to `computed` - All observable api's now default to `any` for their generic arguments - Improved `flow` cancellation - The effect of `when` is now automatically an action. - `@computed` properties are now declared on their owner rather then the protoptype. Fixes an issue where `@computed` fields didn't work in React Native on proxied objects. See [#1396](https://github.com/mobxjs/mobx/issues/1396) - `action` and `action.bound` decorated fields are now reassignable, so that they can be stubbed ## 4.0.2 - Fixed issue where exceptions like `TypeError: Cannot define property:__mobxDidRunLazyInitializers, object is not extensible.` were thrown. Fixes [#1404](https://github.com/mobxjs/mobx/issues/1404) - Improved flow typings for `flow`, [#1399](https://github.com/mobxjs/mobx/pull/1399) by @ismailhabib ## 4.0.1 - Updated flow typings, see [#1393](https://github.com/mobxjs/mobx/pull/1393) by [andrew--r](https://github.com/andrew--r) ## 4.0.0 - For the highlights of this release, read the [blog](https://medium.com/p/c1fbc08008da/): - For migration notes: see the [wiki page](https://github.com/mobxjs/mobx/wiki/Migrating-from-mobx-3-to-mobx-4) - Note; many things that were removed to make the api surface smaller. If you think some feature shouldn't have been removed, feel free to open an issue! This is the extensive list of all changes. ### New features The changes mentioned here are discussed in detail in the [release highlights](https://medium.com/p/c1fbc08008da/), or were simply updated in the docs. - MobX 4 introduces separation between the production and non production build. The production build strips most typechecks, resulting in a faster and smaller build. Make sure to substitute process.env.NODE_ENV = "production" in your build process! If you are using MobX in a react project, you most probably already have set this up. Otherwise, the idea is explained [here](https://reactjs.org/docs/add-react-to-an-existing-app.html). - Introduced `flow` to create a chain of async actions. This is the same function as [`asyncActions`](https://github.com/mobxjs/mobx-utils#asyncaction) of the mobx-utils package - These `flow`'s are now cancellable, by calling `.cancel()` on the returned promise, which will throw a cancellation exception into the generator function. - `flow` also has experimental support for async iterators (`async * function`) - Introduced `decorate(thing, decorators)` to decorate classes or object without needing decorator syntax. - Introduced `onBecomeObserved` and `onBecomeUnobserved`. These API's enable hooking into the observability system and get notified about when an observable starts / stops becoming used. This is great to automaticaly fetch data from external resources, or stop doing so. - `computed` / `@computed` now accepts a `requiresReaction` option. If it set, the computed value will throw an exception if it is being read while not being tracked by some reaction. - To make `requiresReaction` the default, use `mobx.configure({ computedRequiresReaction: true })` - Introduced `mobx.configure({ disableErrorBoundaries })`, for easier debugging of exceptoins. By [NaridaL](https://github.com/NaridaL) through [#1262](https://github.com/mobxjs/mobx/pull/1262) - `toJS` now accepts the options: `{ detectCycles?: boolean, exportMapsAsObjects?: boolean }`, both `true` by default - Observable maps are now backed by real ES6 Maps. This means that any value can be used as key now, not just strings and numbers. - The flow typings have been updated. Since this is a manual effort, there can be mistakes, so feel free to PR! - `computed(fn, options?)` / `@computed(options) get fn()` now accept the following options: - `set: (value) => void` to set a custom setter on the computed property - `name: "debug name"` - `equals: fn` the equality value to use for the computed to determine whether its output has changed. The default is `comparer.default`. Alternatives are `comparer.structural`, `comparer.identity` or just your own comparison function. - `requiresReaction: boolean` see above. - `autorun(fn, options?)` now accepts the following options: - `delay: number` debounce the autorun with the given amount of milliseconds. This replaces the MobX 3 api `autorunAsync` - `name: "debug name"` - `scheduler: function` a custom scheduler to run the autorun. For example to connect running the autorun to `requestAnimationFrame`. See the docs for more details - `onError`. A custom error handler to be notified when an autorun throws an exception. - `reaction(expr, effect, options?)` now accepts the following options: - `delay: number` debounce the autorun with the given amount of milliseconds. This replaces the MobX 3 api `autorunAsync` - `fireImmediately`. Immediately fire the effect function after the first evaluation of `expr` - `equals`. Custom equality function to determine whether the `expr` function differed from its previous result, and hence should fire `effect`. Accepts the same options as the `equals` option of computed. - All the options `autorun` accepts - `when(predicate, effect?, options?)` now accepts the following options: - `name: "debug name"` - `onError`. A custom error handler to be notified when an autorun throws an exception. - `timeout: number` a timeout in milliseconds, after which the `onError` handler will be triggered to signal the condition not being met within a certain time - The `effect` parameter of `when` has become optional. If it is omitted, `when` will return a promise. This makes it easy to `await` a condition, for example: `await when(() => user.profile.loaded)`. The returned promise can be cancelled using `promise.cancel()` - There is now an utility API that enables manipulating observable maps, objects and arrays with the same api. These api's are fully reactive, which means that even new property declarations can be detected by mobx if `set` is used to add them, and `values` or `keys` to iterate them. - `values(thing)` returns all values in the collection as array - `keys(thing)` returns all keys in the collection as array - `set(thing, key, value)` or `set(thing, { key: value })` Updates the given collection with the provided key / value pair(s). - `remove(thing, key)` removes the specified child from the collection. For arrays splicing is used. - `has(thing, key)` returns true if the collection has the specified _observable_ property. - `get(thing, key)` returns the chlid under the specified key. - `observable`, `observable.array`, `observable.object`, `observable.map` and `extendObservable` now accept an additional options object, which can specify the following attributes: - `name: "debug name"` - `deep: boolean`. `true` by default, indicates whether the children of this collection are automatically converted into observables as well. - `defaultDecorator: <decorator>` specifies the default decorator used for new children