mobx-state-tree 5.3.0 → 5.3.1-alpha.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/dist/mobx-state-tree.js
CHANGED
|
@@ -5846,62 +5846,47 @@ var defaultObjectOptions = {
|
|
|
5846
5846
|
};
|
|
5847
5847
|
function toPropertiesObject(declaredProps) {
|
|
5848
5848
|
var keysList = Object.keys(declaredProps);
|
|
5849
|
-
var alreadySeenKeys =
|
|
5849
|
+
var alreadySeenKeys = new Set();
|
|
5850
5850
|
keysList.forEach(function (key) {
|
|
5851
|
-
if (alreadySeenKeys
|
|
5852
|
-
throw fail$1(key + " is declared twice in the model. Model should not contain same keys");
|
|
5853
|
-
}
|
|
5854
|
-
else {
|
|
5855
|
-
alreadySeenKeys[key] = true;
|
|
5851
|
+
if (alreadySeenKeys.has(key)) {
|
|
5852
|
+
throw fail$1(key + " is declared twice in the model. Model should not contain the same keys");
|
|
5856
5853
|
}
|
|
5854
|
+
alreadySeenKeys.add(key);
|
|
5857
5855
|
});
|
|
5858
5856
|
// loop through properties and ensures that all items are types
|
|
5859
5857
|
return keysList.reduce(function (props, key) {
|
|
5860
|
-
var _a, _b, _c;
|
|
5861
5858
|
// warn if user intended a HOOK
|
|
5862
|
-
if (key in Hook)
|
|
5859
|
+
if (key in Hook) {
|
|
5863
5860
|
throw fail$1("Hook '" + key + "' was defined as property. Hooks should be defined as part of the actions");
|
|
5864
|
-
|
|
5865
|
-
var descriptor = Object.getOwnPropertyDescriptor(
|
|
5861
|
+
}
|
|
5862
|
+
var descriptor = Object.getOwnPropertyDescriptor(declaredProps, key);
|
|
5866
5863
|
if ("get" in descriptor) {
|
|
5867
5864
|
throw fail$1("Getters are not supported as properties. Please use views instead");
|
|
5868
5865
|
}
|
|
5869
|
-
// undefined and null are not valid
|
|
5870
5866
|
var value = descriptor.value;
|
|
5871
5867
|
if (value === null || value === undefined) {
|
|
5872
5868
|
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)`?");
|
|
5873
|
-
// its a primitive, convert to its type
|
|
5874
5869
|
}
|
|
5875
5870
|
else if (isPrimitive(value)) {
|
|
5876
|
-
|
|
5877
|
-
_a[key] = optional(getPrimitiveFactoryFromValue(value), value),
|
|
5878
|
-
_a));
|
|
5879
|
-
// map defaults to empty object automatically for models
|
|
5871
|
+
props[key] = optional(getPrimitiveFactoryFromValue(value), value);
|
|
5880
5872
|
}
|
|
5881
5873
|
else if (value instanceof MapType) {
|
|
5882
|
-
|
|
5883
|
-
_b[key] = optional(value, {}),
|
|
5884
|
-
_b));
|
|
5874
|
+
props[key] = optional(value, {});
|
|
5885
5875
|
}
|
|
5886
5876
|
else if (value instanceof ArrayType) {
|
|
5887
|
-
|
|
5888
|
-
// its already a type
|
|
5889
|
-
}
|
|
5890
|
-
else if (isType(value)) {
|
|
5891
|
-
return props;
|
|
5892
|
-
// its a function, maybe the user wanted a view?
|
|
5877
|
+
props[key] = optional(value, []);
|
|
5893
5878
|
}
|
|
5879
|
+
else if (isType(value)) ;
|
|
5894
5880
|
else if (devMode() && typeof value === "function") {
|
|
5895
5881
|
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?");
|
|
5896
|
-
// no other complex values
|
|
5897
5882
|
}
|
|
5898
5883
|
else if (devMode() && typeof value === "object") {
|
|
5899
5884
|
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.");
|
|
5900
|
-
// WTF did you pass in mate?
|
|
5901
5885
|
}
|
|
5902
5886
|
else {
|
|
5903
5887
|
throw fail$1("Invalid type definition for property '" + key + "', cannot infer a type from a value like '" + value + "' (" + typeof value + ")");
|
|
5904
5888
|
}
|
|
5889
|
+
return props;
|
|
5905
5890
|
}, declaredProps);
|
|
5906
5891
|
}
|
|
5907
5892
|
/**
|