Changelog History
Page 7
-
v4.1.0 Changes
- Introduced
keepAlive
as option tocomputed
- 0๏ธโฃ 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 -
action
andaction.bound
decorated fields are now reassignable, so that they can be stubbed
- Introduced
-
v4.0.0 Changes
- ๐ For the highlights of this release, read the blog:
- ๐ For migration notes: see the wiki page
- ๐ 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, 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.
- ๐ฆ Introduced
flow
to create a chain of async actions. This is the same function asasyncActions
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
andonBecomeUnobserved
. 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 arequiresReaction
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, usemobx.configure({ computedRequiresReaction: true })
- ๐ง Introduced
mobx.configure({ disableErrorBoundaries })
, for easier debugging of exceptoins. By NaridaL through #1262 - 0๏ธโฃ
toJS
now accepts the options:{ detectCycles?: boolean, exportMapsAsObjects?: boolean }
, bothtrue
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 iscomparer.default
. Alternatives arecomparer.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 apiautorunAsync
-
name: "debug name"
-
scheduler: function
a custom scheduler to run the autorun. For example to connect running the autorun torequestAnimationFrame
. 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 apiautorunAsync
-
fireImmediately
. Immediately fire the effect function after the first evaluation ofexpr
-
equals
. Custom equality function to determine whether theexpr
function differed from its previous result, and hence should fireeffect
. Accepts the same options as theequals
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 theonError
handler will be triggered to signal the condition not being met within a certain time
-
The
effect
parameter ofwhen
has become optional. If it is omitted,when
will return a promise. This makes it easy toawait
a condition, for example:await when(() => user.profile.loaded)
. The returned promise can be cancelled usingpromise.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, andvalues
orkeys
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)
orset(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
andextendObservable
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 toobservable.ref
,observable.struct
etc. (Thedeep
property is just a short-hand for switching betweenobservable.deep
orobservable.ref
as default decorator for new properties)
-
๐ฅ Breaking changes
The changes mentioned here are discussed in detail in the migration notes
- ๐ป 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 severalSymbol
s to exist for its typings. So make sure that thelib
configuration of your project is set to"es6"
. (The compilation target can still be"es5"
) - ๐
observable.shallowArray(values)
has been removed, instead useobservable.array(values, { deep: false })
- ๐
observable.shallowMap(values)
has been removed, instead useobservable.map(values, { deep: false })
- ๐
observable.shallowObject(values)
has been removed, instead useobservable.object(values, {}, { deep: false })
-
extendShallowObservable(target, props)
, instead useextendObservable(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 thedecorators
param to resp.observable.object
andextendObservable
- โก๏ธ The new signature of
extendObservable
isextendObservable(target, props, decorators?, options?)
. This also means it is no longer possible to pass multiple bags of properties toextendObservable
.Update 13-01-2020: the latter limitation has been reverted in MobX 4.15.2 / 5.15.2extendObservable
can no longer be used to re-declare properties. Useset
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]()
andarray[@@iterator]()
no longer return an array, but an iterator. Usemobx.values(map)
orArray.from(map)
to convert the iterators to arrays. - dropped
@computed.equals
, instead, you can now use@computed({ equals: ... })
- ๐ง
useStrict(boolean)
was dropped, useconfigure({ enforceActions: boolean })
instead - ๐ง
isolateGlobalState
was dropped, useconfigure({ 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.
- ๐ฆ 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 justcomputed(fn).get()
- ๐
createTransformer
has been moved to mobx-utils - ๐ Passing
context
explicitly toautorun
,reaction
etc is no longer supported. Use arrow functions or function.bind instead. - ๐ Removed
autorunAsync
. Use thedelay
option ofautorun
instead. - ๐
autorun
,when
,reaction
don't support name as first argument anymore, instead pass thename
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
andisSpyEnabled
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. Callobservable.box(value)
explictly in such cases. -
isComputed
andisObservable
no longer accept a property as second argument. Instead useisComputedProp
andisObservableProp
. - ๐ Removed
whyRun
, usetrace
instead - The spy event signature has slightly changed
- The
Atom
class is no longer exposed. UsecreateAtom
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
andcompareStructural
for computed values are deprecated, use@computed.struct
orcomputed({ equals: comparer.structural})
instead. -
isModifierDescriptor
is no longer exposed. -
deepEqual
is no longer exposed, usecomparer.structural
instead. - โฑ
setReactionScheduler
->configure({ reactionScheduler: fn })
- ๐ง
reserveArrayBuffer
->configure({ reactionErrorHandler: fn })
-
ObservableMap
is no longer exposed as constructor, useobservable.map
orisObservableMap
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 useimport { x } from "mobx"
and notimport 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 by Marc Fallows
- ๐ 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 likeobservable.ref.struct
(this used to beobservable.deep.struct
). That is; values in anobservable.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 - Improve
observable
api - #992 -
onBecomeObserved
&onBecomeUnobserved
- #1301 - Set
onError
handler when creating reactions - #817 - Improve typings of
observe
- #800 - Use
Map
as backend implementation of observable maps - #1361 - Make observableMaps structurally correct maps
- ๐ #813 - Create separate dev and production builds
- #961, #1197 - Make it possible to forbid reading an untracked computed value
- #1098 - Throw instead of warn if multiple MobX instances are active
- #1122 - Atom hooks fired to often for observable maps
- โฑ #1148 - Disposer of reactions should also cancel all scheduled effects
- #1241 - Make it possible to disable error boundaries, to make it easier to find exceptions
- ๐ #1263 - Remove bower.json
-
v3.6.0 Changes
- ๐ Fixed #1118, the deepEquals operator build into mobx gave wrong results for non-primitive objects. This affected for example
computed.struct
, or thecompareStructural
ofreaction
- ๐ Fixed #1118, the deepEquals operator build into mobx gave wrong results for non-primitive objects. This affected for example
-
v3.4.1 Changes
- โก๏ธ Republished 3.4.0, because the package update doesn't seem to distibute consistently through yarn / npm