mobx-state-tree
Advanced tools
Changelog
3.1.1
getParent
and getRoot
. Fixes #951 through #953 by @xaviergonzChangelog
3.0.0
Welcome to MobX-state-tree! This version introduces some breaking changes, but nonetheless is an recommended upgrade as all changes should be pretty straight forward and there is no reason anymore to maintain the 2.x range (3.0 is still compatible with MobX 4)
MST 3 is twice as fast in initializing trees with half the memory consumption compared to version 2:
Running yarn speedtest
on Node 9.3:
| | MST 2 | MST 3 | | --------------- | ------ | ------ | | Time | 24sec | 12 sec | | Mem | 315MB | 168MB | | Size (min+gzip) | 14.1KB | 15.0KB |
Beyond that, MST 3 uses TypeScript 2.8, which results in more accurate TypeScript support.
The type system has been simplified and improved in several areas. Several open issues around maps and (numeric) keys have been resolved. The frozen
type can now be fully typed. See below for the full details.
Also, the 'object has died' exception can be suppressed now. One should still address it, but at least it won't be a show-stopper from now on.
types.identifier
can no longer be parameterized with either types.string
or types.number
. So instead of types.identifier()
use types.identifier
. Identifiers are now always normalized to strings. This reflects what was already happening internally and solves a lot of edge cases. To use numbers as identifiers, types.identifierNumber
(instead of types.identifier(types.number)
) can be used, which serializes it's snapshot to a number, but will internally work like a string based identifiertypes.maybe
now serializes to / from undefined
by default, as it is more and more the common best practice to don't use null
at all and MST follows this practice. Use types.maybeNull
for the old behavior (see #830)types.frozen
is now a function, and can now be invoked in a few different ways:
types.frozen()
- behaves the same as types.frozen
in MST 2.types.frozen(SubType)
- provide a valid MST type and frozen will check if the provided data conforms the snapshot for that type. Note that the type will not actually be instantiated, so it can only be used to check the shape of the data. Adding views or actions to SubType
would be pointless.types.frozen(someDefaultValue)
- provide a primitive value, object or array, and MST will infer the type from that object, and also make it the default value for the fieldtypes.frozen<TypeScriptType>()
- provide a typescript type, to help in strongly typing the field (design time only)types.map
or types.array
in types.optional
when used in a model
type, map
and array
are now optional by default when used as property type. See #906postProcessSnapshot
can no longer be declared as action, but, like preProcessSnapshot
, needs to be defined on the type rather than on the instance.types.union
is now eager, which means that if multiple valid types for a value are encountered, the first valid type is picked, rather then throwing. #907 / #804, dispatcher
param => option,map.put
will now return the inserted node, rather than the map itself. This makes it easier to find objects for which the identifier is not known upfront. See #766 by k-g-aafterCreate
hook will now only be fired upon instantiation of the tree node, which now happens lazily (on first read / action). The internal order in which hooks are fired within a single node has remained the same. See #845 for detailssetLivelynessChecking("warn" | "ignore" | "error")
, this can be used to customize how MST should act when one tries to read or write to a node that has already been removed from the tree. The default behavior is warn
.model.compose
, see #892 by t49trangetPath
could return stale results, fixes #917types.identifier(types.number)
=> types.identifierNumber
types.identifier()
and types.identifier(types.string)
=>types.identifier
types.frozen
=> types.frozen()
types.maybe(x)
=> types.maybeNull(x)
postProcessSnapshot
should now be declared on the type instead of as actionChangelog
2.2.0
Changelog
2.1.0
types.frozen
where not applied correctly after apply snapshot. #842 by SirbyAlive. Fixes #643flow
s of destroyed nodes can no 'safely' resume. #798 by Bnaya. Fixes #792Snapshot
is exposed. #821 by dsabanin