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