mobx-state-tree 5.3.1-alpha.1 → 5.4.0-pre.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -28,51 +28,51 @@ See the [Getting started](https://mobx-state-tree.js.org/intro/getting-started)
|
|
|
28
28
|
There's nothing quite like looking at some code to get a feel for a library. Check out this small example of an author and list of tweets by that author.
|
|
29
29
|
|
|
30
30
|
```js
|
|
31
|
-
import { types } from "mobx-state-tree"
|
|
31
|
+
import { types } from "mobx-state-tree" // alternatively: import { t } from "mobx-state-tree"
|
|
32
32
|
|
|
33
33
|
// Define a couple models
|
|
34
34
|
const Author = types.model({
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
id: types.identifier,
|
|
36
|
+
firstName: types.string,
|
|
37
|
+
lastName: types.string
|
|
38
38
|
})
|
|
39
39
|
const Tweet = types.model({
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
id: types.identifier,
|
|
41
|
+
author: types.reference(Author), // stores just the `id` reference!
|
|
42
|
+
body: types.string,
|
|
43
|
+
timestamp: types.number
|
|
44
44
|
})
|
|
45
45
|
|
|
46
46
|
// Define a store just like a model
|
|
47
47
|
const RootStore = types.model({
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
authors: types.array(Author),
|
|
49
|
+
tweets: types.array(Tweet)
|
|
50
50
|
})
|
|
51
51
|
|
|
52
52
|
// Instantiate a couple model instances
|
|
53
53
|
const jamon = Author.create({
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
id: "jamon",
|
|
55
|
+
firstName: "Jamon",
|
|
56
|
+
lastName: "Holmgren"
|
|
57
57
|
})
|
|
58
58
|
|
|
59
59
|
const tweet = Tweet.create({
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
60
|
+
id: "1",
|
|
61
|
+
author: jamon.id, // just the ID needed here
|
|
62
|
+
body: "Hello world!",
|
|
63
|
+
timestamp: Date.now()
|
|
64
64
|
})
|
|
65
65
|
|
|
66
66
|
// Now instantiate the store!
|
|
67
67
|
const rootStore = RootStore.create({
|
|
68
|
-
|
|
69
|
-
|
|
68
|
+
authors: [jamon],
|
|
69
|
+
tweets: [tweet]
|
|
70
70
|
})
|
|
71
71
|
|
|
72
72
|
// Ready to use in a React component, if that's your target.
|
|
73
73
|
import { observer } from "mobx-react-lite"
|
|
74
74
|
const MyComponent = observer((props) => {
|
|
75
|
-
|
|
75
|
+
return <div>Hello, {rootStore.authors[0].firstName}!</div>
|
|
76
76
|
})
|
|
77
77
|
|
|
78
78
|
// Note: since this component is "observed", any changes to rootStore.authors[0].firstName
|
|
@@ -82,9 +82,9 @@ const MyComponent = observer((props) => {
|
|
|
82
82
|
|
|
83
83
|
## Thanks!
|
|
84
84
|
|
|
85
|
-
-
|
|
86
|
-
-
|
|
87
|
-
-
|
|
88
|
-
-
|
|
89
|
-
-
|
|
90
|
-
-
|
|
85
|
+
- [Michel Weststrate](https://twitter.com/mweststrate) for creating MobX, MobX-State-Tree, and MobX-React.
|
|
86
|
+
- [Infinite Red](https://infinite.red) for supporting ongoing maintenance on MST.
|
|
87
|
+
- [Mendix](https://mendix.com) for sponsoring and providing the opportunity to work on exploratory projects like MST.
|
|
88
|
+
- [Dan Abramov](https://twitter.com/dan_abramov)'s work on [Redux](http://redux.js.org) has strongly influenced the idea of snapshots and transactional actions in MST.
|
|
89
|
+
- [Giulio Canti](https://twitter.com/GiulioCanti)'s work on [tcomb](http://github.com/gcanti/tcomb) and type systems in general has strongly influenced the type system of MST.
|
|
90
|
+
- All the early adopters encouraging to pursue this whole idea and proving it is something feasible.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { IModelType, IAnyModelType, IDisposer, IMSTMap, IMapType, IMSTArray, IArrayType, IType, IAnyType, ModelPrimitive, ISimpleType, IComplexType, IAnyComplexType, IReferenceType, _CustomCSProcessor, _CustomOrOther, _CustomJoin, _NotCustomized, typecheck, escapeJsonPath, unescapeJsonPath, joinJsonPath, splitJsonPath, IJsonPatch, IReversibleJsonPatch, decorate, addMiddleware, IMiddlewareEvent, IActionTrackingMiddleware2Call, IMiddlewareHandler, IMiddlewareEventType, IActionTrackingMiddlewareHooks, IActionTrackingMiddleware2Hooks, process, isStateTreeNode, IStateTreeNode, IAnyStateTreeNode, flow, castFlowReturn, applyAction, onAction, IActionRecorder, ISerializedActionCall, recordActions, createActionTrackingMiddleware, createActionTrackingMiddleware2, setLivelinessChecking, getLivelinessChecking, LivelinessMode, setLivelynessChecking, // to be deprecated
|
|
2
2
|
LivelynessMode, // to be deprecated
|
|
3
|
-
ModelSnapshotType, ModelCreationType, ModelSnapshotType2, ModelCreationType2, ModelInstanceType, ModelInstanceTypeProps, ModelPropertiesDeclarationToProperties, ModelProperties, ModelPropertiesDeclaration, ModelActions, ITypeUnion, CustomTypeOptions, UnionOptions, Instance, SnapshotIn, SnapshotOut, SnapshotOrInstance, TypeOrStateTreeNodeToStateTreeNode, UnionStringArray, getType, getChildType, onPatch, onSnapshot, applyPatch, IPatchRecorder, recordPatches, protect, unprotect, isProtected, applySnapshot, getSnapshot, hasParent, getParent, hasParentOfType, getParentOfType, getRoot, getPath, getPathParts, isRoot, resolvePath, resolveIdentifier, getIdentifier, tryResolve, getRelativePath, clone, detach, destroy, isAlive, addDisposer, getEnv, walk, IModelReflectionData, IModelReflectionPropertiesData, IMaybeIType, IMaybe, IMaybeNull, IOptionalIType, OptionalDefaultValueOrFunction, ValidOptionalValue, ValidOptionalValues, getMembers, getPropertyMembers, TypeOfValue, cast, castToSnapshot, castToReferenceSnapshot, isType, isArrayType, isFrozenType, isIdentifierType, isLateType, isLiteralType, isMapType, isModelType, isOptionalType, isPrimitiveType, isReferenceType, isRefinementType, isUnionType, tryReference, isValidReference, OnReferenceInvalidated, OnReferenceInvalidatedEvent, ReferenceOptions, ReferenceOptionsGetSet, ReferenceOptionsOnInvalidated, ReferenceIdentifier, ISnapshotProcessor, ISnapshotProcessors, getNodeId, IActionContext, getRunningActionContext, isActionContextChildOf, isActionContextThisOrChildOf, types,
|
|
3
|
+
ModelSnapshotType, ModelCreationType, ModelSnapshotType2, ModelCreationType2, ModelInstanceType, ModelInstanceTypeProps, ModelPropertiesDeclarationToProperties, ModelProperties, ModelPropertiesDeclaration, ModelActions, ITypeUnion, CustomTypeOptions, UnionOptions, Instance, SnapshotIn, SnapshotOut, SnapshotOrInstance, TypeOrStateTreeNodeToStateTreeNode, UnionStringArray, getType, getChildType, onPatch, onSnapshot, applyPatch, IPatchRecorder, recordPatches, protect, unprotect, isProtected, applySnapshot, getSnapshot, hasParent, getParent, hasParentOfType, getParentOfType, getRoot, getPath, getPathParts, isRoot, resolvePath, resolveIdentifier, getIdentifier, tryResolve, getRelativePath, clone, detach, destroy, isAlive, addDisposer, getEnv, walk, IModelReflectionData, IModelReflectionPropertiesData, IMaybeIType, IMaybe, IMaybeNull, IOptionalIType, OptionalDefaultValueOrFunction, ValidOptionalValue, ValidOptionalValues, getMembers, getPropertyMembers, TypeOfValue, cast, castToSnapshot, castToReferenceSnapshot, isType, isArrayType, isFrozenType, isIdentifierType, isLateType, isLiteralType, isMapType, isModelType, isOptionalType, isPrimitiveType, isReferenceType, isRefinementType, isUnionType, tryReference, isValidReference, OnReferenceInvalidated, OnReferenceInvalidatedEvent, ReferenceOptions, ReferenceOptionsGetSet, ReferenceOptionsOnInvalidated, ReferenceIdentifier, ISnapshotProcessor, ISnapshotProcessors, getNodeId, IActionContext, getRunningActionContext, isActionContextChildOf, isActionContextThisOrChildOf, types, types as t, // We do this as a less ambiguous term for the traditional types module, which sometimes gets confused when discussing "types" in general
|
|
4
|
+
toGeneratorFunction, toGenerator } from "./internal";
|
package/dist/mobx-state-tree.js
CHANGED
|
@@ -5859,27 +5859,34 @@ function toPropertiesObject(declaredProps) {
|
|
|
5859
5859
|
if (key in Hook) {
|
|
5860
5860
|
throw fail$1("Hook '" + key + "' was defined as property. Hooks should be defined as part of the actions");
|
|
5861
5861
|
}
|
|
5862
|
+
// the user intended to use a view
|
|
5862
5863
|
var descriptor = Object.getOwnPropertyDescriptor(declaredProps, key);
|
|
5863
5864
|
if ("get" in descriptor) {
|
|
5864
5865
|
throw fail$1("Getters are not supported as properties. Please use views instead");
|
|
5865
5866
|
}
|
|
5867
|
+
// undefined and null are not valid
|
|
5866
5868
|
var value = descriptor.value;
|
|
5867
5869
|
if (value === null || value === undefined) {
|
|
5868
5870
|
throw fail$1("The default value of an attribute cannot be null or undefined as the type cannot be inferred. Did you mean `types.maybe(someType)`?");
|
|
5869
5871
|
}
|
|
5872
|
+
// its a primitive, convert to its type
|
|
5870
5873
|
else if (isPrimitive(value)) {
|
|
5871
5874
|
props[key] = optional(getPrimitiveFactoryFromValue(value), value);
|
|
5872
5875
|
}
|
|
5876
|
+
// map defaults to empty object automatically for models
|
|
5873
5877
|
else if (value instanceof MapType) {
|
|
5874
5878
|
props[key] = optional(value, {});
|
|
5875
5879
|
}
|
|
5876
5880
|
else if (value instanceof ArrayType) {
|
|
5877
5881
|
props[key] = optional(value, []);
|
|
5878
5882
|
}
|
|
5883
|
+
// its already a type
|
|
5879
5884
|
else if (isType(value)) ;
|
|
5885
|
+
// its a function, maybe the user wanted a view?
|
|
5880
5886
|
else if (devMode() && typeof value === "function") {
|
|
5881
5887
|
throw fail$1("Invalid type definition for property '" + key + "', it looks like you passed a function. Did you forget to invoke it, or did you intend to declare a view / action?");
|
|
5882
5888
|
}
|
|
5889
|
+
// no other complex values
|
|
5883
5890
|
else if (devMode() && typeof value === "object") {
|
|
5884
5891
|
throw fail$1("Invalid type definition for property '" + key + "', it looks like you passed an object. Try passing another model type or a types.frozen.");
|
|
5885
5892
|
}
|
|
@@ -8596,6 +8603,7 @@ exports.resolvePath = resolvePath;
|
|
|
8596
8603
|
exports.setLivelinessChecking = setLivelinessChecking;
|
|
8597
8604
|
exports.setLivelynessChecking = setLivelynessChecking;
|
|
8598
8605
|
exports.splitJsonPath = splitJsonPath;
|
|
8606
|
+
exports.t = types;
|
|
8599
8607
|
exports.toGenerator = toGenerator;
|
|
8600
8608
|
exports.toGeneratorFunction = toGeneratorFunction;
|
|
8601
8609
|
exports.tryReference = tryReference;
|