mobx-state-tree
Advanced tools
Changelog
0.7.0
The type system and internal administration has been refactoring, making the internals both simpler and more flexible. Things like references and identifiers are now first class types, making them much better composable. #152
resolve
is renamed to resolvePath
resolveIdentifier(type, tree, identifier)
to find objects by identifiertypes.reference
is by default non-nullable. For nullable identifiers, use types.maybe(types.reference(X))
isMST
is renamed to isStateTreeNode
Changelog
0.6.2
Changelog
0.6.1
[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.
types.reference
in combination with types.late
, by @robinfehrChangelog
0.6.0
types.withDefault
has been renamed to types.optional
optional
to make them optional in the snapshotmaybe
, union
etctypes.identifier
now also accepts a subtype to override the default string type; e.g. types.identifier(types.number)
Changelog
0.5.1
withDefault
, useful to generate UUID's, timestamps or non-primitive default valuesconst 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 }))
Changelog
0.5.0
getSnapshot
or clone
(#102)types.recursive
has been removed in favor of types.late
unprotect
, to disable protection mode for a certain instance. Useful in afterCreate
hookstypes.late
. Usage: types.late(() => typeDefinition)
. Can be used for circular / recursive type definitions, even across files. See test/circular(1|2).ts
for an example (#74)Changelog
0.4.0
BREAKING types.model
no requires 2 parameters to define a model. The first parameter defines the properties, derived values and view functions. The second argument 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.
Changelog
0.3.3
afterCreate
, afterAttach
, beforeDetach
, beforeDestroy
, implements #76addDisposer(this, cb)
that can be used to easily destruct reactions etc. which are set up in afterCreate
. See #76