mobx-state-tree 5.3.0 → 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.
@@ -5842,23 +5842,21 @@ 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[key]) {
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");
5857
+ }
5860
5858
  // the user intended to use a view
5861
- var descriptor = Object.getOwnPropertyDescriptor(props, key);
5859
+ var descriptor = Object.getOwnPropertyDescriptor(declaredProps, key);
5862
5860
  if ("get" in descriptor) {
5863
5861
  throw fail$1("Getters are not supported as properties. Please use views instead");
5864
5862
  }
@@ -5866,38 +5864,32 @@ function toPropertiesObject(declaredProps) {
5866
5864
  var value = descriptor.value;
5867
5865
  if (value === null || value === undefined) {
5868
5866
  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
5867
  }
5868
+ // its a primitive, convert to its type
5871
5869
  else if (isPrimitive(value)) {
5872
- return Object.assign({}, props, (_a = {},
5873
- _a[key] = optional(getPrimitiveFactoryFromValue(value), value),
5874
- _a));
5875
- // map defaults to empty object automatically for models
5870
+ props[key] = optional(getPrimitiveFactoryFromValue(value), value);
5876
5871
  }
5872
+ // map defaults to empty object automatically for models
5877
5873
  else if (value instanceof MapType) {
5878
- return Object.assign({}, props, (_b = {},
5879
- _b[key] = optional(value, {}),
5880
- _b));
5874
+ props[key] = optional(value, {});
5881
5875
  }
5882
5876
  else if (value instanceof ArrayType) {
5883
- return Object.assign({}, props, (_c = {}, _c[key] = optional(value, []), _c));
5884
- // its already a type
5885
- }
5886
- else if (isType(value)) {
5887
- return props;
5888
- // its a function, maybe the user wanted a view?
5877
+ props[key] = optional(value, []);
5889
5878
  }
5879
+ // its already a type
5880
+ else if (isType(value)) ;
5881
+ // its a function, maybe the user wanted a view?
5890
5882
  else if (devMode() && typeof value === "function") {
5891
5883
  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
5884
  }
5885
+ // no other complex values
5894
5886
  else if (devMode() && typeof value === "object") {
5895
5887
  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
5888
  }
5898
5889
  else {
5899
5890
  throw fail$1("Invalid type definition for property '" + key + "', cannot infer a type from a value like '" + value + "' (" + typeof value + ")");
5900
5891
  }
5892
+ return props;
5901
5893
  }, declaredProps);
5902
5894
  }
5903
5895
  /**
@@ -8539,4 +8531,4 @@ var types = {
8539
8531
  snapshotProcessor: snapshotProcessor
8540
8532
  };
8541
8533
 
8542
- export { addDisposer, addMiddleware, applyAction, applyPatch, applySnapshot, cast, castFlowReturn, castToReferenceSnapshot, castToSnapshot, clone, createActionTrackingMiddleware, createActionTrackingMiddleware2, decorate, destroy, detach, escapeJsonPath, flow, getChildType, getEnv, getIdentifier, getLivelinessChecking, getMembers, getNodeId, getParent, getParentOfType, getPath, getPathParts, getPropertyMembers, getRelativePath, getRoot, getRunningActionContext, getSnapshot, getType, hasParent, hasParentOfType, isActionContextChildOf, isActionContextThisOrChildOf, isAlive, isArrayType, isFrozenType, isIdentifierType, isLateType, isLiteralType, isMapType, isModelType, isOptionalType, isPrimitiveType, isProtected, isReferenceType, isRefinementType, isRoot, isStateTreeNode, isType, isUnionType, isValidReference, joinJsonPath, onAction, onPatch, onSnapshot, process$1 as process, protect, recordActions, recordPatches, resolveIdentifier, resolvePath, setLivelinessChecking, setLivelynessChecking, splitJsonPath, toGenerator, toGeneratorFunction, tryReference, tryResolve, typecheck, types, unescapeJsonPath, unprotect, walk };
8534
+ export { addDisposer, addMiddleware, applyAction, applyPatch, applySnapshot, cast, castFlowReturn, castToReferenceSnapshot, castToSnapshot, clone, createActionTrackingMiddleware, createActionTrackingMiddleware2, decorate, destroy, detach, escapeJsonPath, flow, getChildType, getEnv, getIdentifier, getLivelinessChecking, getMembers, getNodeId, getParent, getParentOfType, getPath, getPathParts, getPropertyMembers, getRelativePath, getRoot, getRunningActionContext, getSnapshot, getType, hasParent, hasParentOfType, isActionContextChildOf, isActionContextThisOrChildOf, isAlive, isArrayType, isFrozenType, isIdentifierType, isLateType, isLiteralType, isMapType, isModelType, isOptionalType, isPrimitiveType, isProtected, isReferenceType, isRefinementType, isRoot, isStateTreeNode, isType, isUnionType, isValidReference, joinJsonPath, onAction, onPatch, onSnapshot, process$1 as process, protect, recordActions, recordPatches, resolveIdentifier, resolvePath, setLivelinessChecking, setLivelynessChecking, splitJsonPath, types as t, toGenerator, toGeneratorFunction, tryReference, tryResolve, typecheck, types, unescapeJsonPath, unprotect, walk };
@@ -5824,23 +5824,21 @@
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[key]) {
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");
5839
+ }
5842
5840
  // the user intended to use a view
5843
- var descriptor = Object.getOwnPropertyDescriptor(props, key);
5841
+ var descriptor = Object.getOwnPropertyDescriptor(declaredProps, key);
5844
5842
  if ("get" in descriptor) {
5845
5843
  throw fail$1("Getters are not supported as properties. Please use views instead");
5846
5844
  }
@@ -5848,38 +5846,32 @@
5848
5846
  var value = descriptor.value;
5849
5847
  if (value === null || value === undefined) {
5850
5848
  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
5849
  }
5850
+ // its a primitive, convert to its type
5853
5851
  else if (isPrimitive(value)) {
5854
- return Object.assign({}, props, (_a = {},
5855
- _a[key] = optional(getPrimitiveFactoryFromValue(value), value),
5856
- _a));
5857
- // map defaults to empty object automatically for models
5852
+ props[key] = optional(getPrimitiveFactoryFromValue(value), value);
5858
5853
  }
5854
+ // map defaults to empty object automatically for models
5859
5855
  else if (value instanceof MapType) {
5860
- return Object.assign({}, props, (_b = {},
5861
- _b[key] = optional(value, {}),
5862
- _b));
5856
+ props[key] = optional(value, {});
5863
5857
  }
5864
5858
  else if (value instanceof ArrayType) {
5865
- return Object.assign({}, props, (_c = {}, _c[key] = optional(value, []), _c));
5866
- // its already a type
5867
- }
5868
- else if (isType(value)) {
5869
- return props;
5870
- // its a function, maybe the user wanted a view?
5859
+ props[key] = optional(value, []);
5871
5860
  }
5861
+ // its already a type
5862
+ else if (isType(value)) ;
5863
+ // its a function, maybe the user wanted a view?
5872
5864
  else if (typeof value === "function") {
5873
5865
  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
5866
  }
5867
+ // no other complex values
5876
5868
  else if (typeof value === "object") {
5877
5869
  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
5870
  }
5880
5871
  else {
5881
5872
  throw fail$1("Invalid type definition for property '" + key + "', cannot infer a type from a value like '" + value + "' (" + typeof value + ")");
5882
5873
  }
5874
+ return props;
5883
5875
  }, declaredProps);
5884
5876
  }
5885
5877
  /**
@@ -8589,6 +8581,7 @@
8589
8581
  exports.setLivelinessChecking = setLivelinessChecking;
8590
8582
  exports.setLivelynessChecking = setLivelynessChecking;
8591
8583
  exports.splitJsonPath = splitJsonPath;
8584
+ exports.t = types;
8592
8585
  exports.toGenerator = toGenerator;
8593
8586
  exports.toGeneratorFunction = toGeneratorFunction;
8594
8587
  exports.tryReference = tryReference;