A type which is equivalent to the union of SnapshotIn and Instance types of a given typeof TYPE or typeof VARIABLE.
For primitives it defaults to the primitive itself.
For example:
@@ -387,12 +387,12 @@
SnapshotOut
Ƭ SnapshotOut: T extends object ? T["SnapshotType"] : T extends IStateTreeNode ? IT["SnapshotType"] : T
types.identifier - Identifiers are used to make references, lifecycle events and reconciling works.
Inside a state tree, for each type can exist only one instance for each given identifier.
For example there couldn't be 2 instances of user with id 1. If you need more, consider using references.
@@ -466,7 +466,7 @@
Const identifierNumber
• identifierNumber: ISimpleType‹number› = new IdentifierNumberType()
Use this utility to register a function that should be called whenever the
targeted state tree node is destroyed. This is a useful alternative to managing
cleanup methods yourself using the beforeDestroy hook.
Middleware can be used to intercept any action is invoked on the subtree where it is attached.
If a tree is protected (by default), this means that any mutation of the tree will pass through your middleware.
Applies an action or a series of actions in a single MobX transaction.
Does not return any value
Takes an action description as produced by the onAction middleware.
Casts a node snapshot or instance type to an instance type so it can be assigned to a type instance.
Note that this is just a cast for the type system, this is, it won't actually convert a snapshot to an instance,
but just fool typescript into thinking so.
@@ -721,7 +721,7 @@
Casts a node snapshot or instance type to an instance type so it can be assigned to a type instance.
Note that this is just a cast for the type system, this is, it won't actually convert a snapshot to an instance,
but just fool typescript into thinking so.
@@ -760,7 +760,7 @@
Casts a node instance type to a reference snapshot type so it can be assigned to a reference snapshot (e.g. to be used inside a create call).
Note that this is just a cast for the type system, this is, it won't actually convert an instance to a reference snapshot,
but just fool typescript into thinking so.
@@ -816,7 +816,7 @@
castToSnapshot
▸ castToSnapshot<I>(snapshotOrInstance: I): Extract<I, IAnyStateTreeNode> extends never ? I : TypeOfValue["CreationType"]
Casts a node instance type to a snapshot type so it can be assigned to a type snapshot (e.g. to be used inside a create call).
Note that this is just a cast for the type system, this is, it won't actually convert an instance to a snapshot,
but just fool typescript into thinking so.
@@ -853,7 +853,7 @@
clone
▸ clone<T>(source: T, keepEnvironment: boolean | any): T
Returns a deep copy of the given state tree node as new tree.
Shorthand for snapshot(x) = getType(x).create(getSnapshot(x))
Tip: clone will create a literal copy, including the same identifiers. To modify identifiers etc. during cloning, don't use clone but take a snapshot of the tree, modify it, and create new instance
types.compose - Composes a new model from one or more existing model types.
This method can be invoked in two forms:
Given 2 or more model types, the types are composed into a new Type.
@@ -901,7 +901,7 @@
Returns:IModelType‹PA & PB, OA & OB, _CustomJoin‹FCA, FCB›, _CustomJoin‹FSA, FSB››
types.compose - Composes a new model from one or more existing model types.
This method can be invoked in two forms:
Given 2 or more model types, the types are composed into a new Type.
@@ -928,7 +928,7 @@
Returns:IModelType‹PA & PB, OA & OB, _CustomJoin‹FCA, FCB›, _CustomJoin‹FSA, FSB››
types.compose - Composes a new model from one or more existing model types.
This method can be invoked in two forms:
Given 2 or more model types, the types are composed into a new Type.
@@ -961,7 +961,7 @@
Returns:IModelType‹PA & PB & PC, OA & OB & OC, _CustomJoin‹FCA, _CustomJoin‹FCB, FCC››, _CustomJoin‹FSA, _CustomJoin‹FSB, FSC›››
types.compose - Composes a new model from one or more existing model types.
This method can be invoked in two forms:
Given 2 or more model types, the types are composed into a new Type.
@@ -993,7 +993,7 @@
Returns:IModelType‹PA & PB & PC, OA & OB & OC, _CustomJoin‹FCA, _CustomJoin‹FCB, FCC››, _CustomJoin‹FSA, _CustomJoin‹FSB, FSC›››
types.compose - Composes a new model from one or more existing model types.
This method can be invoked in two forms:
Given 2 or more model types, the types are composed into a new Type.
@@ -1031,7 +1031,7 @@
Returns:IModelType‹PA & PB & PC & PD, OA & OB & OC & OD, _CustomJoin‹FCA, _CustomJoin‹FCB, _CustomJoin‹FCC, FCD›››, _CustomJoin‹FSA, _CustomJoin‹FSB, _CustomJoin‹FSC, FSD››››
types.compose - Composes a new model from one or more existing model types.
This method can be invoked in two forms:
Given 2 or more model types, the types are composed into a new Type.
@@ -1068,7 +1068,7 @@
Returns:IModelType‹PA & PB & PC & PD, OA & OB & OC & OD, _CustomJoin‹FCA, _CustomJoin‹FCB, _CustomJoin‹FCC, FCD›››, _CustomJoin‹FSA, _CustomJoin‹FSB, _CustomJoin‹FSC, FSD››››
types.compose - Composes a new model from one or more existing model types.
This method can be invoked in two forms:
Given 2 or more model types, the types are composed into a new Type.
@@ -1111,7 +1111,7 @@
Returns:IModelType‹PA & PB & PC & PD & PE, OA & OB & OC & OD & OE, _CustomJoin‹FCA, _CustomJoin‹FCB, _CustomJoin‹FCC, _CustomJoin‹FCD, FCE››››, _CustomJoin‹FSA, _CustomJoin‹FSB, _CustomJoin‹FSC, _CustomJoin‹FSD, FSE›››››
types.compose - Composes a new model from one or more existing model types.
This method can be invoked in two forms:
Given 2 or more model types, the types are composed into a new Type.
@@ -1153,7 +1153,7 @@
Returns:IModelType‹PA & PB & PC & PD & PE, OA & OB & OC & OD & OE, _CustomJoin‹FCA, _CustomJoin‹FCB, _CustomJoin‹FCC, _CustomJoin‹FCD, FCE››››, _CustomJoin‹FSA, _CustomJoin‹FSB, _CustomJoin‹FSC, _CustomJoin‹FSD, FSE›››››
types.compose - Composes a new model from one or more existing model types.
This method can be invoked in two forms:
Given 2 or more model types, the types are composed into a new Type.
@@ -1201,7 +1201,7 @@
Returns:IModelType‹PA & PB & PC & PD & PE & PF, OA & OB & OC & OD & OE & OF, _CustomJoin‹FCA, _CustomJoin‹FCB, _CustomJoin‹FCC, _CustomJoin‹FCD, _CustomJoin‹FCE, FCF›››››, _CustomJoin‹FSA, _CustomJoin‹FSB, _CustomJoin‹FSC, _CustomJoin‹FSD, _CustomJoin‹FSE, FSF››››››
types.compose - Composes a new model from one or more existing model types.
This method can be invoked in two forms:
Given 2 or more model types, the types are composed into a new Type.
@@ -1248,7 +1248,7 @@
Returns:IModelType‹PA & PB & PC & PD & PE & PF, OA & OB & OC & OD & OE & OF, _CustomJoin‹FCA, _CustomJoin‹FCB, _CustomJoin‹FCC, _CustomJoin‹FCD, _CustomJoin‹FCE, FCF›››››, _CustomJoin‹FSA, _CustomJoin‹FSB, _CustomJoin‹FSC, _CustomJoin‹FSD, _CustomJoin‹FSE, FSF››››››
types.compose - Composes a new model from one or more existing model types.
This method can be invoked in two forms:
Given 2 or more model types, the types are composed into a new Type.
@@ -1301,7 +1301,7 @@
Returns:IModelType‹PA & PB & PC & PD & PE & PF & PG, OA & OB & OC & OD & OE & OF & OG, _CustomJoin‹FCA, _CustomJoin‹FCB, _CustomJoin‹FCC, _CustomJoin‹FCD, _CustomJoin‹FCE, _CustomJoin‹FCF, FCG››››››, _CustomJoin‹FSA, _CustomJoin‹FSB, _CustomJoin‹FSC, _CustomJoin‹FSD, _CustomJoin‹FSE, _CustomJoin‹FSF, FSG›››››››
types.compose - Composes a new model from one or more existing model types.
This method can be invoked in two forms:
Given 2 or more model types, the types are composed into a new Type.
@@ -1353,7 +1353,7 @@
Returns:IModelType‹PA & PB & PC & PD & PE & PF & PG, OA & OB & OC & OD & OE & OF & OG, _CustomJoin‹FCA, _CustomJoin‹FCB, _CustomJoin‹FCC, _CustomJoin‹FCD, _CustomJoin‹FCE, _CustomJoin‹FCF, FCG››››››, _CustomJoin‹FSA, _CustomJoin‹FSB, _CustomJoin‹FSC, _CustomJoin‹FSD, _CustomJoin‹FSE, _CustomJoin‹FSF, FSG›››››››
types.compose - Composes a new model from one or more existing model types.
This method can be invoked in two forms:
Given 2 or more model types, the types are composed into a new Type.
@@ -1411,7 +1411,7 @@
Returns:IModelType‹PA & PB & PC & PD & PE & PF & PG & PH, OA & OB & OC & OD & OE & OF & OG & OH, _CustomJoin‹FCA, _CustomJoin‹FCB, _CustomJoin‹FCC, _CustomJoin‹FCD, _CustomJoin‹FCE, _CustomJoin‹FCF, _CustomJoin‹FCG, FCH›››››››, _CustomJoin‹FSA, _CustomJoin‹FSB, _CustomJoin‹FSC, _CustomJoin‹FSD, _CustomJoin‹FSE, _CustomJoin‹FSF, _CustomJoin‹FSG, FSH››››››››
types.compose - Composes a new model from one or more existing model types.
This method can be invoked in two forms:
Given 2 or more model types, the types are composed into a new Type.
@@ -1468,7 +1468,7 @@
Returns:IModelType‹PA & PB & PC & PD & PE & PF & PG & PH, OA & OB & OC & OD & OE & OF & OG & OH, _CustomJoin‹FCA, _CustomJoin‹FCB, _CustomJoin‹FCC, _CustomJoin‹FCD, _CustomJoin‹FCE, _CustomJoin‹FCF, _CustomJoin‹FCG, FCH›››››››, _CustomJoin‹FSA, _CustomJoin‹FSB, _CustomJoin‹FSC, _CustomJoin‹FSD, _CustomJoin‹FSE, _CustomJoin‹FSF, _CustomJoin‹FSG, FSH››››››››
types.compose - Composes a new model from one or more existing model types.
This method can be invoked in two forms:
Given 2 or more model types, the types are composed into a new Type.
@@ -1531,7 +1531,7 @@
Returns:IModelType‹PA & PB & PC & PD & PE & PF & PG & PH & PI, OA & OB & OC & OD & OE & OF & OG & OH & OI, _CustomJoin‹FCA, _CustomJoin‹FCB, _CustomJoin‹FCC, _CustomJoin‹FCD, _CustomJoin‹FCE, _CustomJoin‹FCF, _CustomJoin‹FCG, _CustomJoin‹FCH, FCI››››››››, _CustomJoin‹FSA, _CustomJoin‹FSB, _CustomJoin‹FSC, _CustomJoin‹FSD, _CustomJoin‹FSE, _CustomJoin‹FSF, _CustomJoin‹FSG, _CustomJoin‹FSH, FSI›››››››››
types.compose - Composes a new model from one or more existing model types.
This method can be invoked in two forms:
Given 2 or more model types, the types are composed into a new Type.
@@ -1595,7 +1595,7 @@
Note: Consider migrating to createActionTrackingMiddleware2, it is easier to use.
Convenience utility to create action based middleware that supports async processes more easily.
All hooks are called for both synchronous and asynchronous actions. Except that either onSuccess or onFail is called
types.custom - Creates a custom type. Custom types can be used for arbitrary immutable values, that have a serializable representation. For example, to create your own Date representation, Decimal type etc.
types.frozen - Frozen can be used to store any value that is serializable in itself (that is valid JSON).
Frozen values need to be immutable or treated as if immutable. They need be serializable as well.
Values stored in frozen will snapshotted as-is by MST, and internal changes will not be tracked.
types.frozen - Frozen can be used to store any value that is serializable in itself (that is valid JSON).
Frozen values need to be immutable or treated as if immutable. They need be serializable as well.
Values stored in frozen will snapshotted as-is by MST, and internal changes will not be tracked.
types.frozen - Frozen can be used to store any value that is serializable in itself (that is valid JSON).
Frozen values need to be immutable or treated as if immutable. They need be serializable as well.
Values stored in frozen will snapshotted as-is by MST, and internal changes will not be tracked.
Returns the declared type of the given sub property of an object, array or map.
In the case of arrays and maps the property name is optional and will be ignored.
Returns a reflection of the model node, including name, properties, views, volatile state,
and actions. flowActions is also provided as a separate array of names for any action that
came from a flow generator as well.
Returns the unique node id (not to be confused with the instance identifier) for a
given instance.
This id is a number that is unique for each instance.
Calculates a snapshot from the given model instance. The snapshot will always reflect the latest state but use
structural sharing where possible. Doesn't require MobX transactions to be completed.
Returns true if the given state tree node is not killed yet.
This means that the node is still a part of a tree, and that destroy
has not been called. If a node is not alive anymore, the only thing one can do with it
@@ -2340,7 +2340,7 @@
isArrayType
▸ isArrayType<Items>(type: IAnyType): type is IArrayType
Returns true if the given value is a node in a state tree.
More precisely, that is, if the value is an instance of a
types.model, types.array or types.map.
types.late - Defines a type that gets implemented later. This is useful when you have to deal with circular dependencies.
Please notice that when defining circular dependencies TypeScript isn't smart enough to inference them.
types.late - Defines a type that gets implemented later. This is useful when you have to deal with circular dependencies.
Please notice that when defining circular dependencies TypeScript isn't smart enough to inference them.
Example:
@@ -2681,7 +2681,7 @@
lazy
▸ lazy<T, U>(name: string, options: LazyOptions‹T, U›): T
types.literal - The literal type will return a type that will match only the exact given type.
The given value must be a primitive, in order to be serialized to a snapshot correctly.
You can use literal to match exact strings for example the exact male or female string.
types.map - Creates a key based collection type who's children are all of a uniform declared type.
If the type stored in a map has an identifier, it is mandatory to store the child under that identifier in the map.
Registers a function that will be invoked for each action that is called on the provided model instance, or to any of its children.
See actions for more details. onAction events are emitted only for the outermost called action in the stack.
Action can also be intercepted by middleware using addMiddleware to change the function call before it will be run.
Registers a function that will be invoked for each mutation that is applied to the provided model instance, or to any of its children.
See patches for more details. onPatch events are emitted immediately and will not await the end of a transaction.
Patches can be used to deeply observe a model tree.
Registers a function that is invoked whenever a new snapshot for the given model instance is available.
The listener will only be fire at the end of the current MobX (trans)action.
See snapshots for more details.
Small abstraction around onAction and applyAction, attaches an action listener to a tree and records all the actions emitted.
Returns an recorder object with the following signature:
Small abstraction around onPatch and applyPatch, attaches a patch listener to a tree and records all the patches.
Returns a recorder object with the following signature:
types.refinement - Creates a type that is more specific than the base type, e.g. types.refinement(types.string, value => value.length > 5) to create a type of strings that can only be longer then 5.
types.refinement - Creates a type that is more specific than the base type, e.g. types.refinement(types.string, value => value.length > 5) to create a type of strings that can only be longer then 5.
types.safeReference - A safe reference is like a standard reference, except that it accepts the undefined value by default
and automatically sets itself to undefined (when the parent is a model) / removes itself from arrays and maps
when the reference it is pointing to gets detached/destroyed.
types.safeReference - A safe reference is like a standard reference, except that it accepts the undefined value by default
and automatically sets itself to undefined (when the parent is a model) / removes itself from arrays and maps
when the reference it is pointing to gets detached/destroyed.
Defines what MST should do when running into reads / writes to objects that have died.
By default it will print a warning.
Use the "error" option to easy debugging to see where the error was thrown and when the offending read / write took place
Tests if a reference is valid (pointing to an existing node and optionally if alive) and returns such reference if the check passes,
else it returns undefined.
Type parameters:
@@ -3417,7 +3417,7 @@
tryResolve
▸ tryResolve(target: IAnyStateTreeNode, path: string): any
Run's the typechecker for the given type on the given value, which can be a snapshot or an instance.
Throws if the given value is not according the provided type specification.
Use this if you need typechecks even in a production build (by default all automatic runtime type checks will be skipped in production builds)
types.union - Create a union of multiple types. If the correct type cannot be inferred unambiguously from a snapshot, provide a dispatcher function of the form (snapshot) => Type.
types.union - Create a union of multiple types. If the correct type cannot be inferred unambiguously from a snapshot, provide a dispatcher function of the form (snapshot) => Type.
types.union - Create a union of multiple types. If the correct type cannot be inferred unambiguously from a snapshot, provide a dispatcher function of the form (snapshot) => Type.
types.union - Create a union of multiple types. If the correct type cannot be inferred unambiguously from a snapshot, provide a dispatcher function of the form (snapshot) => Type.
types.union - Create a union of multiple types. If the correct type cannot be inferred unambiguously from a snapshot, provide a dispatcher function of the form (snapshot) => Type.
types.union - Create a union of multiple types. If the correct type cannot be inferred unambiguously from a snapshot, provide a dispatcher function of the form (snapshot) => Type.
types.union - Create a union of multiple types. If the correct type cannot be inferred unambiguously from a snapshot, provide a dispatcher function of the form (snapshot) => Type.
types.union - Create a union of multiple types. If the correct type cannot be inferred unambiguously from a snapshot, provide a dispatcher function of the form (snapshot) => Type.
types.union - Create a union of multiple types. If the correct type cannot be inferred unambiguously from a snapshot, provide a dispatcher function of the form (snapshot) => Type.
types.union - Create a union of multiple types. If the correct type cannot be inferred unambiguously from a snapshot, provide a dispatcher function of the form (snapshot) => Type.
types.union - Create a union of multiple types. If the correct type cannot be inferred unambiguously from a snapshot, provide a dispatcher function of the form (snapshot) => Type.
types.union - Create a union of multiple types. If the correct type cannot be inferred unambiguously from a snapshot, provide a dispatcher function of the form (snapshot) => Type.
types.union - Create a union of multiple types. If the correct type cannot be inferred unambiguously from a snapshot, provide a dispatcher function of the form (snapshot) => Type.
types.union - Create a union of multiple types. If the correct type cannot be inferred unambiguously from a snapshot, provide a dispatcher function of the form (snapshot) => Type.
types.union - Create a union of multiple types. If the correct type cannot be inferred unambiguously from a snapshot, provide a dispatcher function of the form (snapshot) => Type.
types.union - Create a union of multiple types. If the correct type cannot be inferred unambiguously from a snapshot, provide a dispatcher function of the form (snapshot) => Type.
types.union - Create a union of multiple types. If the correct type cannot be inferred unambiguously from a snapshot, provide a dispatcher function of the form (snapshot) => Type.
types.union - Create a union of multiple types. If the correct type cannot be inferred unambiguously from a snapshot, provide a dispatcher function of the form (snapshot) => Type.
types.union - Create a union of multiple types. If the correct type cannot be inferred unambiguously from a snapshot, provide a dispatcher function of the form (snapshot) => Type.
types.union - Create a union of multiple types. If the correct type cannot be inferred unambiguously from a snapshot, provide a dispatcher function of the form (snapshot) => Type.
types.union - Create a union of multiple types. If the correct type cannot be inferred unambiguously from a snapshot, provide a dispatcher function of the form (snapshot) => Type.
types.union - Create a union of multiple types. If the correct type cannot be inferred unambiguously from a snapshot, provide a dispatcher function of the form (snapshot) => Type.
types.union - Create a union of multiple types. If the correct type cannot be inferred unambiguously from a snapshot, provide a dispatcher function of the form (snapshot) => Type.
types.union - Create a union of multiple types. If the correct type cannot be inferred unambiguously from a snapshot, provide a dispatcher function of the form (snapshot) => Type.
types.union - Create a union of multiple types. If the correct type cannot be inferred unambiguously from a snapshot, provide a dispatcher function of the form (snapshot) => Type.
types.union - Create a union of multiple types. If the correct type cannot be inferred unambiguously from a snapshot, provide a dispatcher function of the form (snapshot) => Type.
types.union - Create a union of multiple types. If the correct type cannot be inferred unambiguously from a snapshot, provide a dispatcher function of the form (snapshot) => Type.
types.union - Create a union of multiple types. If the correct type cannot be inferred unambiguously from a snapshot, provide a dispatcher function of the form (snapshot) => Type.
types.union - Create a union of multiple types. If the correct type cannot be inferred unambiguously from a snapshot, provide a dispatcher function of the form (snapshot) => Type.
types.union - Create a union of multiple types. If the correct type cannot be inferred unambiguously from a snapshot, provide a dispatcher function of the form (snapshot) => Type.
types.union - Create a union of multiple types. If the correct type cannot be inferred unambiguously from a snapshot, provide a dispatcher function of the form (snapshot) => Type.
types.union - Create a union of multiple types. If the correct type cannot be inferred unambiguously from a snapshot, provide a dispatcher function of the form (snapshot) => Type.
types.union - Create a union of multiple types. If the correct type cannot be inferred unambiguously from a snapshot, provide a dispatcher function of the form (snapshot) => Type.
types.union - Create a union of multiple types. If the correct type cannot be inferred unambiguously from a snapshot, provide a dispatcher function of the form (snapshot) => Type.
By default it is not allowed to directly modify a model. Models can only be modified through actions.
However, in some cases you don't care about the advantages (like replayability, traceability, etc) this yields.
For example because you are building a PoC or don't have any middleware attached to your tree.
TypeScript support is best-effort as not all patterns can be expressed in TypeScript. Except for assigning snapshots to properties we get pretty close! As MST uses the latest fancy TypeScript features it is required to use TypeScript 3.0 or later with noImplicitThis and strictNullChecks enabled.
-Actually, the more strict options that are enabled, the better the type system will behave.
+
TypeScript support is best-effort as not all patterns can be expressed in TypeScript. Except for assigning snapshots to properties we get pretty close! As MST uses the latest fancy TypeScript features it is required to use TypeScript 3.0 or later with noImplicitThis and strictNullChecks enabled.
+
The more strict options that are enabled, the better the type system will behave.
Recommend compiler flags
The recommended compiler flags (against which all our tests are written) are:
TypeScript support is best-effort as not all patterns can be expressed in TypeScript. Except for assigning snapshots to properties we get pretty close! As MST uses the latest fancy TypeScript features it is required to use TypeScript 3.0 or later with noImplicitThis and strictNullChecks enabled.
-Actually, the more strict options that are enabled, the better the type system will behave.
+
TypeScript support is best-effort as not all patterns can be expressed in TypeScript. Except for assigning snapshots to properties we get pretty close! As MST uses the latest fancy TypeScript features it is required to use TypeScript 3.0 or later with noImplicitThis and strictNullChecks enabled.
+
The more strict options that are enabled, the better the type system will behave.
Recommend compiler flags
The recommended compiler flags (against which all our tests are written) are: