mobx-state-tree 7.0.0 → 7.0.2

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.
@@ -59,7 +59,7 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
59
59
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
60
60
  PERFORMANCE OF THIS SOFTWARE.
61
61
  ***************************************************************************** */
62
- /* global Reflect, Promise, SuppressedError, Symbol */
62
+ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
63
63
 
64
64
  var extendStatics = function(d, b) {
65
65
  extendStatics = Object.setPrototypeOf ||
@@ -100,8 +100,8 @@ function __rest(s, e) {
100
100
  }
101
101
 
102
102
  function __generator(thisArg, body) {
103
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
104
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
103
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
104
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
105
105
  function verb(n) { return function (v) { return step([n, v]); }; }
106
106
  function step(op) {
107
107
  if (f) throw new TypeError("Generator is already executing.");
@@ -1797,7 +1797,9 @@ var ObjectNode = /** @class */ (function (_super) {
1797
1797
  if (!this.parent && newParent.root === this) {
1798
1798
  throw new MstError("A state tree is not allowed to contain itself. Cannot assign ".concat(this, " to path '").concat(newParent.path, "/").concat(subpath, "'"));
1799
1799
  }
1800
- if (!this.parent && !!this.environment && this.environment !== newParent.root.environment) {
1800
+ if (!this.parent &&
1801
+ !!this.environment &&
1802
+ this.environment !== newParent.root.environment) {
1801
1803
  throw new MstError("A state tree cannot be made part of another state tree as long as their environments are different.");
1802
1804
  }
1803
1805
  }
@@ -1821,7 +1823,9 @@ var ObjectNode = /** @class */ (function (_super) {
1821
1823
  value: function (name) {
1822
1824
  var _this = this;
1823
1825
  this.fireInternalHook(name);
1824
- var fn = this.storedValue && typeof this.storedValue === "object" && this.storedValue[name];
1826
+ var fn = this.storedValue &&
1827
+ typeof this.storedValue === "object" &&
1828
+ this.storedValue[name];
1825
1829
  if (typeof fn === "function") {
1826
1830
  // we check for it to allow old mobx peer dependencies that don't have the method to work (even when still bugged)
1827
1831
  if (_allowStateChangesInsideComputed) {
@@ -1926,7 +1930,8 @@ var ObjectNode = /** @class */ (function (_super) {
1926
1930
  var actionFullPath = "";
1927
1931
  if (actionContext && actionContext.name != null) {
1928
1932
  // try to use the context, and if it not available use the node one
1929
- var actionPath = (actionContext && actionContext.context && getPath(actionContext.context)) || escapedPath;
1933
+ var actionPath = (actionContext && actionContext.context && getPath(actionContext.context)) ||
1934
+ escapedPath;
1930
1935
  actionFullPath = "".concat(actionPath, ".").concat(actionContext.name, "()");
1931
1936
  }
1932
1937
  return "You are trying to read or write to an object that is no longer part of a state tree. (Object type: '".concat(this.type.name, "', Path upon death: '").concat(escapedPath, "', Subpath: '").concat(subpath, "', Action: '").concat(actionFullPath, "'). Either detach nodes first, or don't use objects after removing / replacing them in the tree.");
@@ -2561,7 +2566,8 @@ var ComplexType = /** @class */ (function (_super) {
2561
2566
  writable: true,
2562
2567
  value: function (current, snapshot) {
2563
2568
  return (!current.identifierAttribute ||
2564
- current.identifier === normalizeIdentifier(snapshot[current.identifierAttribute]));
2569
+ current.identifier ===
2570
+ normalizeIdentifier(snapshot[current.identifierAttribute]));
2565
2571
  }
2566
2572
  });
2567
2573
  Object.defineProperty(ComplexType.prototype, "tryToReconcileNode", {
@@ -2959,7 +2965,8 @@ function serializeArgument(node, actionName, index, arg) {
2959
2965
  if (typeof arg === "function")
2960
2966
  return serializeTheUnserializable("[function]");
2961
2967
  if (typeof arg === "object" && !isPlainObject(arg) && !isArray(arg))
2962
- return serializeTheUnserializable("[object ".concat((arg && arg.constructor && arg.constructor.name) || "Complex Object", "]"));
2968
+ return serializeTheUnserializable("[object ".concat((arg && arg.constructor && arg.constructor.name) ||
2969
+ "Complex Object", "]"));
2963
2970
  try {
2964
2971
  // Check if serializable, cycle free etc...
2965
2972
  // MWE: there must be a better way....
@@ -3215,7 +3222,8 @@ function createActionInvoker(target, name, fn) {
3215
3222
  tree: getRoot(target),
3216
3223
  rootId: parentContext ? parentContext.rootId : id,
3217
3224
  parentId: parentContext ? parentContext.id : 0,
3218
- allParentIds: parentContext ? __spreadArray(__spreadArray([], __read(parentContext.allParentIds), false), [parentContext.id], false) : [],
3225
+ allParentIds: parentContext
3226
+ ? __spreadArray(__spreadArray([], __read(parentContext.allParentIds), false), [parentContext.id], false) : [],
3219
3227
  parentEvent: parentContext,
3220
3228
  parentActionEvent: parentActionContext
3221
3229
  }, fn);
@@ -3809,7 +3817,7 @@ function getRelativePathBetweenNodes(base, target) {
3809
3817
  break;
3810
3818
  }
3811
3819
  // TODO: assert that no targetParts paths are "..", "." or ""!
3812
- return baseParts.slice(common).map(doubleDot).join("/") + joinJsonPath(targetParts.slice(common));
3820
+ return (baseParts.slice(common).map(doubleDot).join("/") + joinJsonPath(targetParts.slice(common)));
3813
3821
  }
3814
3822
  /**
3815
3823
  * @internal
@@ -4057,7 +4065,8 @@ function deepFreeze(value) {
4057
4065
  freeze(value);
4058
4066
  if (isPlainObject(value)) {
4059
4067
  Object.keys(value).forEach(function (propKey) {
4060
- if (!isPrimitive(value[propKey]) && !Object.isFrozen(value[propKey])) {
4068
+ if (!isPrimitive(value[propKey]) &&
4069
+ !Object.isFrozen(value[propKey])) {
4061
4070
  deepFreeze(value[propKey]);
4062
4071
  }
4063
4072
  });
@@ -6984,7 +6993,9 @@ function refinement() {
6984
6993
  var name = typeof args[0] === "string" ? args.shift() : isType(args[0]) ? args[0].name : null;
6985
6994
  var type = args[0];
6986
6995
  var predicate = args[1];
6987
- var message = args[2] ? args[2] : function (v) { return "Value does not respect the refinement predicate"; };
6996
+ var message = args[2]
6997
+ ? args[2]
6998
+ : function (v) { return "Value does not respect the refinement predicate"; };
6988
6999
  // ensures all parameters are correct
6989
7000
  assertIsType(type, [1, 2]);
6990
7001
  assertIsString(name, 1);
@@ -7606,7 +7617,8 @@ var Lazy = /** @class */ (function (_super) {
7606
7617
  when(function () {
7607
7618
  return _this.pendingNodeList.length > 0 &&
7608
7619
  _this.pendingNodeList.some(function (node) {
7609
- return node.isAlive && _this.options.shouldLoadPredicate(node.parent ? node.parent.value : null);
7620
+ return node.isAlive &&
7621
+ _this.options.shouldLoadPredicate(node.parent ? node.parent.value : null);
7610
7622
  });
7611
7623
  }, function () {
7612
7624
  _this.options.loadType().then(action(function (type) {
@@ -8120,7 +8132,9 @@ var IdentifierReferenceType = /** @class */ (function (_super) {
8120
8132
  configurable: true,
8121
8133
  writable: true,
8122
8134
  value: function (parent, subpath, environment, initialValue) {
8123
- var identifier = isStateTreeNode(initialValue) ? getIdentifier(initialValue) : initialValue;
8135
+ var identifier = isStateTreeNode(initialValue)
8136
+ ? getIdentifier(initialValue)
8137
+ : initialValue;
8124
8138
  var storedRef = new StoredReference(initialValue, this.targetType);
8125
8139
  var storedRefNode = createScalarNode(this, parent, subpath, environment, storedRef);
8126
8140
  storedRef.node = storedRefNode;
@@ -8205,7 +8219,9 @@ var CustomReferenceType = /** @class */ (function (_super) {
8205
8219
  var newIdentifier = isStateTreeNode(newValue)
8206
8220
  ? this.options.set(newValue, current ? current.storedValue : null)
8207
8221
  : newValue;
8208
- if (!current.isDetaching && current.type === this && current.storedValue === newIdentifier) {
8222
+ if (!current.isDetaching &&
8223
+ current.type === this &&
8224
+ current.storedValue === newIdentifier) {
8209
8225
  current.setParent(parent, subpath);
8210
8226
  return current;
8211
8227
  }
@@ -63,7 +63,7 @@
63
63
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
64
64
  PERFORMANCE OF THIS SOFTWARE.
65
65
  ***************************************************************************** */
66
- /* global Reflect, Promise, SuppressedError, Symbol */
66
+ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
67
67
 
68
68
  var extendStatics = function(d, b) {
69
69
  extendStatics = Object.setPrototypeOf ||
@@ -104,8 +104,8 @@
104
104
  }
105
105
 
106
106
  function __generator(thisArg, body) {
107
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
108
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
107
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
108
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
109
109
  function verb(n) { return function (v) { return step([n, v]); }; }
110
110
  function step(op) {
111
111
  if (f) throw new TypeError("Generator is already executing.");
@@ -1801,7 +1801,9 @@
1801
1801
  if (!this.parent && newParent.root === this) {
1802
1802
  throw new MstError("A state tree is not allowed to contain itself. Cannot assign ".concat(this, " to path '").concat(newParent.path, "/").concat(subpath, "'"));
1803
1803
  }
1804
- if (!this.parent && !!this.environment && this.environment !== newParent.root.environment) {
1804
+ if (!this.parent &&
1805
+ !!this.environment &&
1806
+ this.environment !== newParent.root.environment) {
1805
1807
  throw new MstError("A state tree cannot be made part of another state tree as long as their environments are different.");
1806
1808
  }
1807
1809
  }
@@ -1825,7 +1827,9 @@
1825
1827
  value: function (name) {
1826
1828
  var _this = this;
1827
1829
  this.fireInternalHook(name);
1828
- var fn = this.storedValue && typeof this.storedValue === "object" && this.storedValue[name];
1830
+ var fn = this.storedValue &&
1831
+ typeof this.storedValue === "object" &&
1832
+ this.storedValue[name];
1829
1833
  if (typeof fn === "function") {
1830
1834
  // we check for it to allow old mobx peer dependencies that don't have the method to work (even when still bugged)
1831
1835
  if (mobx._allowStateChangesInsideComputed) {
@@ -1930,7 +1934,8 @@
1930
1934
  var actionFullPath = "";
1931
1935
  if (actionContext && actionContext.name != null) {
1932
1936
  // try to use the context, and if it not available use the node one
1933
- var actionPath = (actionContext && actionContext.context && getPath(actionContext.context)) || escapedPath;
1937
+ var actionPath = (actionContext && actionContext.context && getPath(actionContext.context)) ||
1938
+ escapedPath;
1934
1939
  actionFullPath = "".concat(actionPath, ".").concat(actionContext.name, "()");
1935
1940
  }
1936
1941
  return "You are trying to read or write to an object that is no longer part of a state tree. (Object type: '".concat(this.type.name, "', Path upon death: '").concat(escapedPath, "', Subpath: '").concat(subpath, "', Action: '").concat(actionFullPath, "'). Either detach nodes first, or don't use objects after removing / replacing them in the tree.");
@@ -2565,7 +2570,8 @@
2565
2570
  writable: true,
2566
2571
  value: function (current, snapshot) {
2567
2572
  return (!current.identifierAttribute ||
2568
- current.identifier === normalizeIdentifier(snapshot[current.identifierAttribute]));
2573
+ current.identifier ===
2574
+ normalizeIdentifier(snapshot[current.identifierAttribute]));
2569
2575
  }
2570
2576
  });
2571
2577
  Object.defineProperty(ComplexType.prototype, "tryToReconcileNode", {
@@ -2963,7 +2969,8 @@
2963
2969
  if (typeof arg === "function")
2964
2970
  return serializeTheUnserializable("[function]");
2965
2971
  if (typeof arg === "object" && !isPlainObject(arg) && !isArray(arg))
2966
- return serializeTheUnserializable("[object ".concat((arg && arg.constructor && arg.constructor.name) || "Complex Object", "]"));
2972
+ return serializeTheUnserializable("[object ".concat((arg && arg.constructor && arg.constructor.name) ||
2973
+ "Complex Object", "]"));
2967
2974
  try {
2968
2975
  // Check if serializable, cycle free etc...
2969
2976
  // MWE: there must be a better way....
@@ -3219,7 +3226,8 @@
3219
3226
  tree: getRoot(target),
3220
3227
  rootId: parentContext ? parentContext.rootId : id,
3221
3228
  parentId: parentContext ? parentContext.id : 0,
3222
- allParentIds: parentContext ? __spreadArray(__spreadArray([], __read(parentContext.allParentIds), false), [parentContext.id], false) : [],
3229
+ allParentIds: parentContext
3230
+ ? __spreadArray(__spreadArray([], __read(parentContext.allParentIds), false), [parentContext.id], false) : [],
3223
3231
  parentEvent: parentContext,
3224
3232
  parentActionEvent: parentActionContext
3225
3233
  }, fn);
@@ -3813,7 +3821,7 @@
3813
3821
  break;
3814
3822
  }
3815
3823
  // TODO: assert that no targetParts paths are "..", "." or ""!
3816
- return baseParts.slice(common).map(doubleDot).join("/") + joinJsonPath(targetParts.slice(common));
3824
+ return (baseParts.slice(common).map(doubleDot).join("/") + joinJsonPath(targetParts.slice(common)));
3817
3825
  }
3818
3826
  /**
3819
3827
  * @internal
@@ -4057,7 +4065,8 @@
4057
4065
  freeze(value);
4058
4066
  if (isPlainObject(value)) {
4059
4067
  Object.keys(value).forEach(function (propKey) {
4060
- if (!isPrimitive(value[propKey]) && !Object.isFrozen(value[propKey])) {
4068
+ if (!isPrimitive(value[propKey]) &&
4069
+ !Object.isFrozen(value[propKey])) {
4061
4070
  deepFreeze(value[propKey]);
4062
4071
  }
4063
4072
  });
@@ -6966,7 +6975,9 @@
6966
6975
  var name = typeof args[0] === "string" ? args.shift() : isType(args[0]) ? args[0].name : null;
6967
6976
  var type = args[0];
6968
6977
  var predicate = args[1];
6969
- var message = args[2] ? args[2] : function (v) { return "Value does not respect the refinement predicate"; };
6978
+ var message = args[2]
6979
+ ? args[2]
6980
+ : function (v) { return "Value does not respect the refinement predicate"; };
6970
6981
  // ensures all parameters are correct
6971
6982
  assertIsType(type, [1, 2]);
6972
6983
  assertIsString(name, 1);
@@ -7588,7 +7599,8 @@
7588
7599
  mobx.when(function () {
7589
7600
  return _this.pendingNodeList.length > 0 &&
7590
7601
  _this.pendingNodeList.some(function (node) {
7591
- return node.isAlive && _this.options.shouldLoadPredicate(node.parent ? node.parent.value : null);
7602
+ return node.isAlive &&
7603
+ _this.options.shouldLoadPredicate(node.parent ? node.parent.value : null);
7592
7604
  });
7593
7605
  }, function () {
7594
7606
  _this.options.loadType().then(mobx.action(function (type) {
@@ -8102,7 +8114,9 @@
8102
8114
  configurable: true,
8103
8115
  writable: true,
8104
8116
  value: function (parent, subpath, environment, initialValue) {
8105
- var identifier = isStateTreeNode(initialValue) ? getIdentifier(initialValue) : initialValue;
8117
+ var identifier = isStateTreeNode(initialValue)
8118
+ ? getIdentifier(initialValue)
8119
+ : initialValue;
8106
8120
  var storedRef = new StoredReference(initialValue, this.targetType);
8107
8121
  var storedRefNode = createScalarNode(this, parent, subpath, environment, storedRef);
8108
8122
  storedRef.node = storedRefNode;
@@ -8187,7 +8201,9 @@
8187
8201
  var newIdentifier = isStateTreeNode(newValue)
8188
8202
  ? this.options.set(newValue, current ? current.storedValue : null)
8189
8203
  : newValue;
8190
- if (!current.isDetaching && current.type === this && current.storedValue === newIdentifier) {
8204
+ if (!current.isDetaching &&
8205
+ current.type === this &&
8206
+ current.storedValue === newIdentifier) {
8191
8207
  current.setParent(parent, subpath);
8192
8208
  return current;
8193
8209
  }