Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Mobx4 #1321

Merged
merged 204 commits into from
Mar 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
204 commits
Select commit Hold shift + click to select a range
6d71f48
Don't try/catch errors when globalstate.disableErrorBoundaries is on.
NaridaL Dec 4, 2017
2f32c15
Allow autorunAsync to take a debouncing function in addition to a delay
TrentHouliston Jan 15, 2018
7510b81
Add unit test for autorunAsync scheduling function
TrentHouliston Jan 17, 2018
787bf5a
Make types more explicit
TrentHouliston Jan 17, 2018
4077755
Increase time to execute the test for travis
TrentHouliston Jan 17, 2018
9be342e
Update changelog
TrentHouliston Jan 17, 2018
e805559
killed old modifiers
mweststrate Jan 24, 2018
31744bb
Dropped bower support. Fixes #1263
mweststrate Jan 24, 2018
49514b1
Implemented #1089: throw if there are multiple mobx instances
mweststrate Jan 24, 2018
4bcdb97
Fixed exports
mweststrate Jan 24, 2018
53edb5c
Dropped `.extras` namespace
mweststrate Jan 24, 2018
cef553b
Fixing tests
mweststrate Jan 24, 2018
cc5ccd4
Fixed tests :)
mweststrate Jan 24, 2018
df6d17c
`observable(value)` no longer accepts primitives. Use `observable.bo…
mweststrate Jan 24, 2018
b0ce8bc
introduced `isObservableProp` and `isComputedProp`
mweststrate Jan 25, 2018
dd21bc1
Jest cleanup: don't log errors as side effects
mweststrate Jan 25, 2018
15d6a1e
Removed all remaining leaking console logs
mweststrate Jan 25, 2018
dad19a2
Snapshotted whyrun test
mweststrate Jan 25, 2018
78df300
Fixed newline issues
mweststrate Jan 25, 2018
208390f
Whyrun will now print why a computed value / reaction is re-running
mweststrate Jan 25, 2018
b0f37df
fixed state sharing tests
mweststrate Jan 25, 2018
0d4e0a7
Merged in master
mweststrate Feb 6, 2018
3c55d85
Killed whyRun
mweststrate Feb 6, 2018
350efdc
Created a MobX4 todo list
mweststrate Feb 8, 2018
967c557
Improved error messages
mweststrate Feb 15, 2018
53a3d31
upgraded to TS 2.7
mweststrate Feb 15, 2018
6f1829e
cleaned up reaction api
mweststrate Feb 16, 2018
60507a4
Merge branch 'master' of https://github.com/TrentHouliston/mobx into …
mweststrate Feb 16, 2018
6abdb58
Merged #1305 into mobx4, added scheduler support for reactions as well
mweststrate Feb 16, 2018
8390609
Made decorators work with Babel 7 (loose mode only)
mweststrate Feb 16, 2018
9f5eda9
Disabled TS / Babel perf tests by default
mweststrate Feb 16, 2018
51ded3a
Fixed performance tests
mweststrate Feb 16, 2018
1e95ad4
fixed dependency issue with decorators
mweststrate Feb 16, 2018
f5cae00
extendObservable now extends objects in a single batch
mweststrate Feb 17, 2018
26a8b55
Introduced `keys`. Observable objects now have an observable keyset
mweststrate Feb 17, 2018
8b1ae86
Fixed a regression in toJS
mweststrate Feb 17, 2018
e510603
Fixed bug in `extendObservable`; values were not assigned to compute…
mweststrate Feb 17, 2018
aac6729
WIP `values` / `set` / `remove`
mweststrate Feb 17, 2018
5292254
Added tests for `set`, `remove`, `values` and `keys` with several da…
mweststrate Feb 21, 2018
8b4b650
Removed a todo
mweststrate Feb 23, 2018
bbc31c8
Introduced `decorate`
mweststrate Feb 23, 2018
d96e0e0
Removed debugger statement
mweststrate Feb 23, 2018
51d6f74
Added typings & type test for decorate
mweststrate Feb 23, 2018
0cb3568
Migrated spy tests to use snapshots
mweststrate Feb 23, 2018
7f04ff5
spy events now report the name of the observable they are invoked upon.
mweststrate Feb 23, 2018
2c88f33
decorate now supports plain objects as well
mweststrate Feb 23, 2018
c0d4e8f
fixed error handling tests, many were broken...
mweststrate Feb 23, 2018
5135530
WIP improving onbecome(un)observed
mweststrate Feb 23, 2018
701102c
onBecome(Un)Observed are now only triggered for observables that are …
mweststrate Feb 23, 2018
65ef22a
Introduced `createAtom`, little cleanup
mweststrate Feb 23, 2018
8f8cb22
Finished cleanup of createTransformer
mweststrate Feb 23, 2018
c79f843
Map / array api's now properly return iterator objects, instead of co…
mweststrate Feb 26, 2018
f758123
Fixed circular dependency problem with Atoms
mweststrate Feb 26, 2018
1b4863a
Fixed bug in hook disposal
mweststrate Feb 26, 2018
bf7cca8
Fixed incorrect test
mweststrate Feb 26, 2018
8e52f9f
Slightly faster object initialization
mweststrate Feb 26, 2018
a040981
Set up envify for conditional compilation
mweststrate Feb 26, 2018
fd8ab30
Introduced non-production only code for smaller / faster prod bundles
mweststrate Feb 26, 2018
3fcb72d
Cleaned up unused stuff
mweststrate Feb 26, 2018
1ab5ac5
Removed `expr`, now part of mobx-utils
mweststrate Feb 27, 2018
b55c7c0
Added prettier config file
mweststrate Feb 27, 2018
1a74a29
Moved `createTransformer` to mobx-utils package
mweststrate Feb 27, 2018
e79f794
Cleaned a bunch of TODO's
mweststrate Feb 27, 2018
65a0b98
More cleanup!
mweststrate Feb 27, 2018
856aa26
Replaces `useStrict` with `configure`
mweststrate Feb 27, 2018
db3ff5b
Introduced `mobx.configure({ warnOnUnsafeComputationReads: true })`, …
mweststrate Feb 27, 2018
1a4defd
isolateGlobalState has now become a configuration option
mweststrate Feb 27, 2018
8c2f648
Added test to reproduce #1122
mweststrate Feb 27, 2018
ea8f603
Added test to confirm #1148 is fixed
mweststrate Feb 27, 2018
1cde211
Merged changes
mweststrate Feb 27, 2018
8691169
Added unit tests to verify #1241
mweststrate Feb 27, 2018
56a1dcd
Little rename
mweststrate Feb 27, 2018
71f702f
Fixed unnecessary warning when reading map entries
mweststrate Feb 27, 2018
f4601a2
Fixed some typings in typescript tests
mweststrate Feb 27, 2018
1e7539e
Simplified the way computed values are constructed
mweststrate Feb 27, 2018
3fc851c
Added jsconfig file to supress warnings on decorators in babel
mweststrate Feb 27, 2018
54269bb
introduced `@computed(options)`. also introduced `requiresReaction`
mweststrate Feb 27, 2018
601f93d
removing some dead code
mweststrate Feb 27, 2018
a857dca
Implemented #1301: specify onError handler on reactions as option
mweststrate Feb 27, 2018
4e5c6cf
Merge remote-tracking branch 'origin/master' into mobx4
mweststrate Feb 27, 2018
0344e90
Fixed a potential bug in `when`
mweststrate Feb 27, 2018
f111eba
Merge branch 'master' into mobx4
mweststrate Feb 27, 2018
0fa557d
Fixed some compile errors
mweststrate Feb 27, 2018
1b2d947
Fixed regression tests after merging master
mweststrate Feb 27, 2018
b157f41
alpha 1
mweststrate Feb 28, 2018
7931d3b
extendObservable only accepts one arg
mweststrate Feb 28, 2018
e953595
extendObservable now takes an options object
mweststrate Feb 28, 2018
ef4bc3f
Fixed regression performance drop
mweststrate Feb 28, 2018
515e4fc
Fixed compilation error
mweststrate Feb 28, 2018
5833fe3
Merge remote-tracking branch 'origin/master' into mobx4
mweststrate Feb 28, 2018
9443b69
Stop exposing `deepEqual` to outside world. Use `comparer.structural`…
mweststrate Feb 28, 2018
9b70833
Merged #817
mweststrate Feb 28, 2018
04d3fe6
Merged #800
mweststrate Feb 28, 2018
e3e4907
Fixed tests
mweststrate Feb 28, 2018
32caff5
Fixed compilation error
mweststrate Feb 28, 2018
458f32e
More tests
mweststrate Feb 28, 2018
259e87c
Map definition is now based on es2015.collection
mweststrate Feb 28, 2018
be4ad7f
Enabled toJS to return Maps
mweststrate Feb 28, 2018
2dba343
Merge branch 'maps' into mobx4
mweststrate Feb 28, 2018
3bde5bc
fixed performance tests
mweststrate Feb 28, 2018
ac73be4
Simplified computed api
mweststrate Mar 1, 2018
1d5250e
naive extendObservable implementation
mweststrate Mar 1, 2018
0bf1c41
Made extendObservable stricter
mweststrate Mar 1, 2018
e4ff32d
observables test now passes
mweststrate Mar 1, 2018
6c41659
Added unit test for decorate
mweststrate Mar 1, 2018
5e31c81
Fixed some tests
mweststrate Mar 1, 2018
7695f97
`set` can now take a bag of arguments
mweststrate Mar 1, 2018
33023e8
extend now supports decorators
mweststrate Mar 1, 2018
f1b09ab
`observable.object` now accepts decorators
mweststrate Mar 1, 2018
4dabbee
Fixed most tests
mweststrate Mar 1, 2018
9fd1366
Structure etc works again
mweststrate Mar 1, 2018
bb5edeb
Killed modifiers :)
mweststrate Mar 1, 2018
ccfec38
test cleanup
mweststrate Mar 1, 2018
ea85186
Tiny improvements
mweststrate Mar 1, 2018
73bf899
Deprecated shallow api
mweststrate Mar 1, 2018
820286a
alpha 2
mweststrate Mar 1, 2018
f5a1892
todo's
mweststrate Mar 1, 2018
aaf71bd
WIP: optimizing initialization by skipping decorator
mweststrate Mar 1, 2018
21a1880
more notes
mweststrate Mar 1, 2018
be049dc
some cleanup
mweststrate Mar 1, 2018
d632313
Little restructuring
mweststrate Mar 1, 2018
b4dee43
some fancy tests
mweststrate Mar 2, 2018
42320c8
better decorators underway(?)
mweststrate Mar 2, 2018
7ab27b2
Improved typings of object api
mweststrate Mar 2, 2018
c62631e
Make inheritance work
mweststrate Mar 2, 2018
c8938eb
Fixed auto property initialization
mweststrate Mar 2, 2018
85f7c1c
Improve error on illegal property access
mweststrate Mar 2, 2018
2e9e709
Updated tests for illegal access
mweststrate Mar 2, 2018
bde7707
all observable decorators now use decorators2
mweststrate Mar 2, 2018
9e3877a
All observable decorators now use decorators2
mweststrate Mar 2, 2018
bc936bd
Rewriting computed
mweststrate Mar 2, 2018
36d81fa
Computed now goes through decorators2
mweststrate Mar 2, 2018
2c6c4a4
Cleaner property creation
mweststrate Mar 2, 2018
b7cf088
Support for non-enumerable props
mweststrate Mar 2, 2018
3408d99
Made sure computed props are declared on proto
mweststrate Mar 2, 2018
e5eda2d
Actions on new decorator system part 1
mweststrate Mar 2, 2018
75ecfa5
More efficient action instantiation
mweststrate Mar 2, 2018
4c90629
Added bound action decorator
mweststrate Mar 2, 2018
e73e1c7
Simplifications
mweststrate Mar 2, 2018
92d4e37
fixed compilation errors
mweststrate Mar 2, 2018
8b7e847
make mobx.observable also accept options
mweststrate Mar 3, 2018
78446a5
simplified extendObservable / property creation short-circuiting
mweststrate Mar 3, 2018
3bbfcb5
added support for action short-circuiting
mweststrate Mar 3, 2018
0613553
Cleanup
mweststrate Mar 3, 2018
f8008bb
cleanup
mweststrate Mar 3, 2018
390a852
Merge branch 'better-decorators' into improved-observable-api
mweststrate Mar 3, 2018
5014fbe
Merge branch 'improved-observable-api' into mobx4
mweststrate Mar 3, 2018
ec7a543
bugfix in bound actions
mweststrate Mar 3, 2018
eab222e
Cleanup in actions
mweststrate Mar 5, 2018
f80fd49
Processing TODO's
mweststrate Mar 5, 2018
c4a997a
Clean up decrators
mweststrate Mar 5, 2018
20d8dbf
cleanup in observable decorator typings
mweststrate Mar 5, 2018
5f87cdf
Setting new props now preserves existing enhancer
mweststrate Mar 5, 2018
66af4e9
object key additions and removals are now interceptable and observable
mweststrate Mar 5, 2018
cce1468
More todos' processed
mweststrate Mar 5, 2018
4c30db4
processing more todo's!
mweststrate Mar 5, 2018
8c63aad
Merged #1361
mweststrate Mar 5, 2018
9271180
Fixed compile errors
mweststrate Mar 5, 2018
afb3cc1
Added some environment checks
mweststrate Mar 5, 2018
b5f1155
Cleaned up api a bit further
mweststrate Mar 5, 2018
441a315
Throw when using old apis
mweststrate Mar 5, 2018
c6e3088
cleaned up public api
mweststrate Mar 5, 2018
e5f4cf3
Todo's, fixed issues with actions
mweststrate Mar 5, 2018
f539f60
All todo's processed now :)
mweststrate Mar 5, 2018
eaa7f33
Fixed typings issue
mweststrate Mar 5, 2018
6ec78b7
Added `timeout` option to `when`
mweststrate Mar 5, 2018
51a3b88
When will now return a promise if invoked without effect function
mweststrate Mar 5, 2018
168997e
Introduced `flow`
mweststrate Mar 5, 2018
4a522fd
Fixes in typings
mweststrate Mar 5, 2018
f17a983
Little cleanups
mweststrate Mar 5, 2018
ab8680b
Updated flow typings
mweststrate Mar 5, 2018
16b658d
Introduced `has`, `get`
mweststrate Mar 5, 2018
1e81a9f
Release notes stuff
mweststrate Mar 5, 2018
9644470
Updated changelog
mweststrate Mar 6, 2018
a301b71
Fix: computed properties are not considered part of the `keys` collec…
mweststrate Mar 6, 2018
0c59f95
Typing fixes
mweststrate Mar 6, 2018
95c20ec
Typing fix
mweststrate Mar 7, 2018
9125e61
Added vs code config to repo, so others can debug with vscode
mweststrate Mar 7, 2018
3e45406
Fixed module initialization issue
mweststrate Mar 7, 2018
b51c642
code cleanup
mweststrate Mar 7, 2018
bc677c2
Fixed module initialization
mweststrate Mar 7, 2018
8a94211
Beta 2
mweststrate Mar 7, 2018
4e6f084
Changelog fixes
mweststrate Mar 7, 2018
9ce985f
Reproduced and fixed #1376
mweststrate Mar 8, 2018
207c814
Removed unused function
mweststrate Mar 8, 2018
9747018
Removed `dom` stdlib. Fixed some typing issues
mweststrate Mar 8, 2018
c47a05a
Beta 3
mweststrate Mar 8, 2018
d899917
Fixed #1379, CRA refusing to compile mobx.module.js
mweststrate Mar 8, 2018
a65d5f5
Fixed additional compilation issues
mweststrate Mar 8, 2018
565be8a
introduced canceellable flows
mweststrate Mar 9, 2018
9984b12
Additional test
mweststrate Mar 9, 2018
a8354cd
Deprecated array.move and findIndex arguments
mweststrate Mar 10, 2018
ac3f948
Updated readme to MobX 4
mweststrate Mar 10, 2018
5525473
Better error handling setup for reactions
mweststrate Mar 12, 2018
de6c018
Cleaned up `ref.struct` / `deep.struct` decorators
mweststrate Mar 12, 2018
12c7c6f
Merge branch 'master' into mobx4
mweststrate Mar 12, 2018
ac5fe77
Modifiers cleanup
mweststrate Mar 12, 2018
36d690c
Iterator cleanup
mweststrate Mar 12, 2018
b0dbe24
Removed `@flow` decorator; as it's type signature is misleading
mweststrate Mar 12, 2018
9e805b5
Use `generator.return` rather than `throw` for cancellation
mweststrate Mar 12, 2018
fe8131c
Promises cancel recursively
mweststrate Mar 12, 2018
5ab68b1
Anything can now be yielded from flows
mweststrate Mar 12, 2018
cbfbbca
Added support for async iterators
mweststrate Mar 12, 2018
298ce84
Merge branch 'cancellable-flows' into mobx4
mweststrate Mar 12, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ lib
test/babel-tests.js
test/typescript/typescript-tests.js
test/perf/perf.txt
.vscode
dist/
.build*/
.idea
Expand Down
7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"printWidth": 100,
"semi": false,
"tabWidth": 4,
"singleQuote": false,
"useTabs": false
}
17 changes: 17 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [

{
"type": "node",
"request": "launch",
"name": "debug unit test",
"program": "${workspaceRoot}/node_modules/jest/bin/jest.js",
"args": ["-i", "${file}"],
// "preLaunchTask": "tsc: build - tsconfig.json"
}
]
}
18 changes: 18 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"[typescript]": {
"editor.formatOnSave": true,
"editor.formatOnPaste": false
},
"[javascript]": {
"editor.formatOnSave": true,
"editor.formatOnPaste": false
},
// Note, these settings should match lint-staged settings!
"prettier.semi": false,
"prettier.tabWidth": 4,
"prettier.useTabs": false,
"prettier.printWidth": 100,
"prettier.singleQuote": false,
"typescript.tsdk": "node_modules/typescript/lib"
// "javascript.validate.enable": false // enable for flow
}
130 changes: 130 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,133 @@
# 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 were removed to make the api surface smaller. If you thing 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, they 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 it's 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`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this a part of autorun rather than just calling a _.debounce on an existing autorun?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question :) I think the major advantage is that this way the effect is cancellable.

* `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 it's 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 / properties, by default: `observable.deep`, but could be changed to `observable.ref`, `observable.struct` etc. (The `deep` property is just a short-hand for switching between `observable.deep` or `observable.ref` as default decorator for new properties)


### Breaking changes

The changes mentioned here are discussed in detail in the [migration notes](https://github.com/mobxjs/mobx/wiki/Migrating-from-mobx-3-to-mobx-4)

* MobX 4 requires `Map` to be globally available. Polyfill it if targeting IE < 11 or other older browsers.
* For typescript users, MobX now requires `Map` and several `Symbol`s to exist for it's typings. So make sure that the `lib` configuration of your project is set to `"es6"`. (The compilation target can still be `"es5"`)
* `observable.shallowArray(values)` has been removed, instead use `observable.array(values, { deep: false })`
* `observable.shallowMap(values)` has been removed, instead use `observable.map(values, { deep: false })`
* `observable.shallowObject(values)` has been removed, instead use `observable.object(values, {}, { deep: false })`
* `extendShallowObservable(target, props)`, instead use `extendObservable(target, props, {}, { deep: false })`
* The decorators `observable.ref`, `observable.shallow`, `observable.deep`, `observable.struct` can no longer be used as functions. Instead, they should be passed as part of the `decorators` param to resp. `observable.object` and `extendObservable`
* The new signature of `extendObservable` is `extendObservable(target, props, decorators?, options?)`. This also means it is no longer possible to pass multiple bags of properties to `extendObservable`. `extendObservable` can no longer be used to re-declare properties. Use `set` instead to update existing properties (or introduce new ones).
* Iterating maps now follows the spec, that is, `map.values()`, `map.entries()`, `map.keys()`, `map[@@iterator]()` and `array[@@iterator]()` no longer return an array, but an iterator. Use `mobx.values(map)` or `Array.from(map)` to convert the iterators to arrays.
* dropped `@computed.equals`, instead, you can now use `@computed({ equals: ... })`
* `useStrict(boolean)` was dropped, use `configure({ enforceActions: boolean })` instead
* `isolateGlobalState` was dropped, use `configure({ isolateGlobalState: true})` instead
* If there are multiple mobx instances active in a single project, an exception will be thrown. Previously only a warning was printed. Fixes #1098. For details, see [#1082](https://github.com/mobxjs/mobx/issues/1082).
* Dropped the `shareGlobalState` feature. Instead, projects should be setup properly and it is up to the hosting package to make sure that there is only one MobX instance
* `expr` has been moved to mobx-utils. Remember, `expr(fn)` is just `computed(fn).get()`
* `createTransformer` has been moved to mobx-utils
* Passing `context` explicitly to `autorun`, `reaction` etc is no longer supported. Use arrow functions or function.bind instead.
* Removed `autorunAsync`. Use the `delay` option of `autorun` instead.
* `autorun`, `when`, `reaction` don't support name as first argument anymore, instead pass the `name` option.
* The `extras.` namespace has been dropped to enable tree-shaking non-used MobX features. All methods that where there originally are now exported at top level. If they are part of the official public API (you are encouraged to use them) they are exported as is. If they are experimental or somehow internal (you are discouraged to use them), they are prefixed with `_`.
* Dropped bower support. Fixes #1263
* The `spyReportStart`, `spyReportEnd`, `spyReport` and `isSpyEnabled` are no longer public. It is no longer possible to emit custom spy events as to avoid confusing in listeners what the possible set of events is.
* Dropped `isStrictModeEnabled`
* `observable(value)` will only succeed if it can turn the value into an observable data structure (a Map, Array or observable object). But it will no longer create an observable box for other values to avoid confusion. Call `observable.box(value)` explictly in such cases.
* `isComputed` and `isObservable` no longer accept a property as second argument. Instead use `isComputedProp` and `isObservableProp`.
* Removed `whyRun`, use `trace` instead
* The spy event signature has slightly changed
* The `Atom` class is no longer exposed. Use `createAtom` instead (same signature).
* Calling reportObserved() on a self made atom will no longer trigger the hooks if reportObserved is triggered outside a reactive context.
* The options `struct` and `compareStructural` for computed values are deprecated, use `@computed.struct` or `computed({ equals: comparer.structural})` instead.
* `isModifierDescriptor` is no longer exposed.
* `deepEqual` is no longer exposed, use `comparer.structural` instead.
* `setReactionScheduler` -> `configure({ reactionScheduler: fn })`
* `reserveArrayBuffer` -> `configure({ reactionErrorHandler: fn })`
* `ObservableMap` is no longer exposed as constructor, use `observable.map` or `isObservableMap` instead
* `map` -> `observable.map`
* `runInAction` no longer accepts a custom scope
* Dropped the already deprecated and broken `default` export that made it harder to tree-shake mobx. Make sure to always use `import { x } from "mobx"` and not `import mobx from "mobx"`.
* Killed the already deprecated modifiers `asFlat` etc. If you war still using this, see the MobX 2 -> 3 migration notes.
* Observable maps now fully implement the map interface. See [#1361](https://github.com/mobxjs/mobx/pull/1361) by [Marc Fallows](https://github.com/marcfallows)
* Observable arrays will no longer expose the `.move` method
* Dropped the `observable.deep.struct` modifier
* Dropped the `observable.ref.struct` modifier
* `observable.struct` now behaves like `observable.ref.struct` (this used to be `observable.deep.struct`). That is; values in an `observable.struct` field will be stored as is, but structural comparison will be used when assigning a new value
* IReactionDisposer.onError has been removed, use the `onError` option of reactions instead

### Issues fixed in this release:

The issues are incoprorated in the above notes.

* [#1316](https://github.com/mobxjs/mobx/issues/1316) - Improve `observable` api
* [#992](https://github.com/mobxjs/mobx/issues/992) - `onBecomeObserved` & `onBecomeUnobserved`
* [#1301](https://github.com/mobxjs/mobx/issues/1301) - Set `onError` handler when creating reactions
* [#817](https://github.com/mobxjs/mobx/issues/817) - Improve typings of `observe`
* [#800](https://github.com/mobxjs/mobx/issues/800) - Use `Map` as backend implementation of observable maps
* [#1361](https://github.com/mobxjs/mobx/issues/1361) - Make observableMaps structurally correct maps
* [#813](https://github.com/mobxjs/mobx/issues/813) - Create separate dev and production builds
* [#961](https://github.com/mobxjs/mobx/issues/961), [#1197](https://github.com/mobxjs/mobx/issues/1197) - Make it possible to forbid reading an untracked computed value
* [#1098](https://github.com/mobxjs/mobx/issues/1098) - Throw instead of warn if multiple MobX instances are active
* [#1122](https://github.com/mobxjs/mobx/issues/1122) - Atom hooks fired to often for observable maps
* [#1148](https://github.com/mobxjs/mobx/issues/1148) - Disposer of reactions should also cancel all scheduled effects
* [#1241](https://github.com/mobxjs/mobx/issues/1241) - Make it possible to disable error boundaries, to make it easier to find exceptions
* [#1263](https://github.com/mobxjs/mobx/issues/1263) - Remove bower.json

# 3.6.2

Expand Down
43 changes: 19 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ MobX is proudly sponsored by Mendix, Coinbase, Facebook Open Source and many [in

* <i><a style="color: white; background:green;padding:5px;margin:5px;border-radius:2px" href="https://egghead.io/courses/manage-complex-state-in-react-apps-with-mobx">Egghead.io course</a></i>
* [Ten minute, interactive MobX + React tutorial](https://mobxjs.github.io/mobx/getting-started.html)
* [Official MobX 3 documentation and API overview](https://mobxjs.github.io/mobx/refguide/api.html) ([MobX 2](https://github.com/mobxjs/mobx/blob/7c9e7c86e0c6ead141bb0539d33143d0e1f576dd/docs/refguide/api.md))
* [Official MobX 4 documentation and API overview](https://mobxjs.github.io/mobx/refguide/api.html) ([MobX 3](https://github.com/mobxjs/mobx/blob/54557dc319b04e92e31cb87427bef194ec1c549c/docs/refguide/api.md), [MobX 2](https://github.com/mobxjs/mobx/blob/7c9e7c86e0c6ead141bb0539d33143d0e1f576dd/docs/refguide/api.md))
* Videos:
* [ReactNext 2016: Real World MobX](https://www.youtube.com/watch?v=Aws40KOx90U) - 40m [slides](https://docs.google.com/presentation/d/1DrI6Hc2xIPTLBkfNH8YczOcPXQTOaCIcDESdyVfG_bE/edit?usp=sharing)
* [Practical React with MobX](https://www.youtube.com/watch?v=XGwuM_u7UeQ). In depth introduction and explanation to MobX and React by Matt Ruby on OpenSourceNorth (ES5 only) - 42m.
Expand Down Expand Up @@ -69,6 +69,8 @@ MobX adds observable capabilities to existing data structures like objects, arra
This can simply be done by annotating your class properties with the [@observable](http://mobxjs.github.io/mobx/refguide/observable-decorator.html) decorator (ES.Next).

```javascript
import { observable } from "mobx"

class Todo {
id = Math.random();
@observable title = "";
Expand All @@ -78,33 +80,32 @@ class Todo {

Using `observable` is like turning a property of an object into a spreadsheet cell.
But unlike spreadsheets, these values can be not only primitive values, but also references, objects and arrays.
You can even [define your own](http://mobxjs.github.io/mobx/refguide/extending.html) observable data sources.

### Intermezzo: Using MobX in ES5, ES6 and ES.next environments

If these `@` thingies look alien to you, these are ES.next decorators.
Using them is entirely optional in MobX. See the [documentation](http://mobxjs.github.io/mobx/best/decorators.html) for details how to either use or avoid them.
MobX runs on any ES5 environment, but leveraging ES.next features like decorators are the cherry on the pie when using MobX.
The remainder of this readme uses decorators, but remember, _they are optional_.

For example, in good ol' ES5 the above snippet would look like:
If your environment doesn't support decorator syntax, don't worry.
You can read [here](http://mobxjs.github.io/mobx/best/decorators.html) about how to set them up.
Or you can skip them altoghether, as MobX can be used fine without decorator _syntax_, by leveraging the _decorate_ utility.
Many MobX users do prefer the decorator syntax though, as it is slightly more concise.

```javascript
function Todo() {
this.id = Math.random()
extendObservable(this, {
title: "",
finished: false
})
import { decorate, observable } from "mobx"

class Todo {
id = Math.random();
title = "";
finished = false;
}
decorate(Todo, {
title: observable,
finished: observable
})
```

### Computed values

<i><a style="color: white; background:green;padding:5px;margin:5px;border-radius:2px" href="https://egghead.io/lessons/javascript-derive-computed-values-and-manage-side-effects-with-mobx-reactions">Egghead.io lesson 3: computed values</a></i>

With MobX you can define values that will be derived automatically when relevant data is modified.
By using the [`@computed`](http://mobxjs.github.io/mobx/refguide/computed-decorator.html) decorator or by using getter / setter functions when using `(extend)Observable`.
By using the [`@computed`](http://mobxjs.github.io/mobx/refguide/computed-decorator.html) decorator or by using getter / setter functions when using `(extend)Observable` (Of course, you can use `decorate` here again as alternative to the `@` syntax).

```javascript
class TodoList {
Expand Down Expand Up @@ -214,6 +215,7 @@ store.todos[0].finished = true;
```

Nonetheless, MobX has an optional built-in concept of [`actions`](https://mobxjs.github.io/mobx/refguide/action.html).
Read this section as well if you want to now more about writing asynchronous actions. It's easy!
Use them to your advantage; they will help you to structure your code better and make wise decisions about when and where state should be modified.

## MobX: Simple and scalable
Expand Down Expand Up @@ -304,13 +306,6 @@ To use the [flow typings](flow-typed/mobx.js) shipped with MobX:
* In `.flowconfig`, you **cannot** import it explicitly in the `[libs]` section.
* You **do not** need to install library definition using [flow-typed](https://github.com/flowtype/flow-typed).

## Bower support

Bower support is available through the infamous unpkg.com:
`bower install https://unpkg.com/mobx/bower.zip`

Then use `lib/mobx.umd.js` or `lib/mobx.umd.min.js`

## Donating

Was MobX key in making your project a success?
Expand Down
Loading