Fixed issue with array/maps of union types @abruzzihraig Make types.extend support computed attributes @cpunion Fixed issue with map of primitive types and applySnapshot @pioh Better type declarations for union, up to 10 supported types
Fixed issue where arrays where not properly serialized as action argument
- Improved reporting of Type.is(), now it returns a fine grained report of why the provided value is not applicable.
[mobx-state-tree] Error while converting [{}] to AnonymousModel[]:
at path "/name" snapshot undefined is not assignable to type: string.
at path "/quantity" snapshot undefined is not assignable to type: number.
- Fixed support for
types.reference
in combination withtypes.late
, by @robinfehr
- BREAKING
types.withDefault
has been renamed totypes.optional
- BREAKING Array and map types can no longer be left out of snapshots by default. Use
optional
to make them optional in the snapshot - BREAKING Literals no longer have a default value by default (use optional + literal instead)
- BREAKING Disabled inlining type.model definitions as introduced in 0.5.1; to many subtle issues
- Improved identifier support, they are no properly propageted through utility types like
maybe
,union
etc - Fixed issue where fields where not referted back to default when a partial snapshot was provided
- Fixed #122:
types.identifier
now also accepts a subtype to override the default string type; e.g.types.identifier(types.number)
- Introduced support for lazy evaluating values in
withDefault
, useful to generate UUID's, timestamps or non-primitive default values It is now possible to define something likeRemoved in 0.6.0
const Box = types.model({
point: {
x: 10,
y: 10
}
}
Where the type of point
property is inferred to point: types.withDefault(types.model({ x: 10, y: 10}), () => ({ x: 10, y: 10 }))
- ** BREAKING ** protection is now enabled by default (#101)
- ** BREAKING ** it is no longer possible to read values from a dead object. Except through
getSnapshot
orclone
(#102) - ** BREAKING **
types.recursive
has been removed in favor oftypes.late
- Introduced
unprotect
, to disable protection mode for a certain instance. Useful inafterCreate
hooks - Introduced
types.late
. Usage:types.late(() => typeDefinition)
. Can be used for circular / recursive type definitions, even across files. Seetest/circular(1|2).ts
for an example (#74)
BREAKING types.model
no requires 2 parameters to define a model. The first parameter defines the properties, derived values and view functions. The second argment is used to define the actions. For example:
const Todo = types.model("Todo", {
done: types.boolean,
toggle() {
this.done = !this.done
}
})
Now should be defined as:
const Todo = types.model(
"Todo",
{
done: types.boolean,
},
{
toggle() {
this.done = !this.done
}
}
)
It is still possible to define functions on the first object. However, those functions are not considered to be actions, but views. They are not allowed to modify values, but instead should produce a new value themselves.
- Introduced lifecycle hooks
afterCreate
,afterAttach
,beforeDetach
,beforeDestroy
, implements #76 - Introduced the convenience method
addDisposer(this, cb)
that can be used to easily destruct reactions etc. which are set up inafterCreate
. See #76
- Fix: actions where not bound automatically
- Improved and simplified the reconciliation mechanism, fixed many edge cases
- Improved the reference mechanism, fixed many edge cases
- Improved performance
- (re) introduced the concept of environments, which can be passed as second argument to
.create
, and picked up usinggetEnv
- Removed
primitive
type, use a more specific type instead - Improved typescript typings of snapshots
- Added
depth
parameter togetParent
andhasParent
- Separated the concepts of middleware and serializable actions. It is now possible to intercept, modify actions etc through
addMiddleWare
.onAction
now uses middleware, if it is used, all parameters of actions should be serializable!
- Introduced the concept of livelyness; if nodes are removed from the the tree because they are replaced by some other value, they will be marked as "died". This should help to early signal when people hold on to references that are not part of the tree anymore. To explicitly remove an node from a tree, with the intent to spawn a new state tree from it, use
detach
. - Introduced the convenience method
destroy
to remove a model from it's parent and mark it as dead. - Introduced the concept of protected trees. If a tree is protected using
protect
, it can only be modified through action, and not by mutating it directly anymore.
- Introduced .Type and .SnapshotType to be used with TypeScript to get the type for a model
- Renamed
createFactory
totypes.model
(breaking!) - Renamed
composeFactory
totypes.extend
(breaking!) - Actions should now be declared as
name(params) { body }
, instead ofname: action(function (params) { body})
(breaking!) - Models are no longer constructed by invoking the factory as function, but by calling
factory.create
(breaking!) - Introduced
identifier
- Introduced / improved
reference
- Greatly improved typescript support, type inference etc. However there are still limitations as the full typesystem of MST cannot be expressed in TypeScript. Especially concerning the type of snapshots and the possibility to use snapshots as first class value.