mobx-state-tree 5.0.3 → 5.0.4

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.
@@ -1130,6 +1130,14 @@ var BaseNode = /** @class */ (function () {
1130
1130
  enumerable: false,
1131
1131
  configurable: true
1132
1132
  });
1133
+ Object.defineProperty(BaseNode.prototype, "getReconciliationType", {
1134
+ enumerable: false,
1135
+ configurable: true,
1136
+ writable: true,
1137
+ value: function () {
1138
+ return this.type;
1139
+ }
1140
+ });
1133
1141
  Object.defineProperty(BaseNode.prototype, "baseSetParent", {
1134
1142
  enumerable: false,
1135
1143
  configurable: true,
@@ -4586,6 +4594,8 @@ function splitJsonPath(path) {
4586
4594
  return parts;
4587
4595
  }
4588
4596
 
4597
+ /** @hidden */
4598
+ var $preProcessorFailed = Symbol("$preProcessorFailed");
4589
4599
  var SnapshotProcessor = /** @class */ (function (_super) {
4590
4600
  __extends(SnapshotProcessor, _super);
4591
4601
  function SnapshotProcessor(_subtype, _processors, name) {
@@ -4630,6 +4640,19 @@ var SnapshotProcessor = /** @class */ (function (_super) {
4630
4640
  return sn;
4631
4641
  }
4632
4642
  });
4643
+ Object.defineProperty(SnapshotProcessor.prototype, "preProcessSnapshotSafe", {
4644
+ enumerable: false,
4645
+ configurable: true,
4646
+ writable: true,
4647
+ value: function (sn) {
4648
+ try {
4649
+ return this.preProcessSnapshot(sn);
4650
+ }
4651
+ catch (e) {
4652
+ return $preProcessorFailed;
4653
+ }
4654
+ }
4655
+ });
4633
4656
  Object.defineProperty(SnapshotProcessor.prototype, "postProcessSnapshot", {
4634
4657
  enumerable: false,
4635
4658
  configurable: true,
@@ -4653,6 +4676,9 @@ var SnapshotProcessor = /** @class */ (function (_super) {
4653
4676
  node.getSnapshot = function () {
4654
4677
  return _this.postProcessSnapshot(oldGetSnapshot.call(node));
4655
4678
  };
4679
+ node.getReconciliationType = function () {
4680
+ return _this;
4681
+ };
4656
4682
  }
4657
4683
  });
4658
4684
  Object.defineProperty(SnapshotProcessor.prototype, "instantiate", {
@@ -4695,7 +4721,10 @@ var SnapshotProcessor = /** @class */ (function (_super) {
4695
4721
  configurable: true,
4696
4722
  writable: true,
4697
4723
  value: function (value, context) {
4698
- var processedSn = this.preProcessSnapshot(value);
4724
+ var processedSn = this.preProcessSnapshotSafe(value);
4725
+ if (processedSn === $preProcessorFailed) {
4726
+ return typeCheckFailure(context, value, "Failed to preprocess value");
4727
+ }
4699
4728
  return this._subtype.validate(processedSn, context);
4700
4729
  }
4701
4730
  });
@@ -4716,7 +4745,10 @@ var SnapshotProcessor = /** @class */ (function (_super) {
4716
4745
  ? this._subtype
4717
4746
  : isStateTreeNode(thing)
4718
4747
  ? getSnapshot(thing, false)
4719
- : this.preProcessSnapshot(thing);
4748
+ : this.preProcessSnapshotSafe(thing);
4749
+ if (value === $preProcessorFailed) {
4750
+ return false;
4751
+ }
4720
4752
  return this._subtype.validate(value, [{ path: "", type: this._subtype }]).length === 0;
4721
4753
  }
4722
4754
  });
@@ -5736,8 +5768,8 @@ function areSame(oldNode, newValue) {
5736
5768
  oldNode.identifier !== null &&
5737
5769
  oldNode.identifierAttribute &&
5738
5770
  isPlainObject(newValue) &&
5739
- oldNode.type.isMatchingSnapshotId(oldNode, newValue) &&
5740
- oldNode.type.is(newValue));
5771
+ oldNode.type.is(newValue) &&
5772
+ oldNode.type.isMatchingSnapshotId(oldNode, newValue));
5741
5773
  }
5742
5774
  /**
5743
5775
  * Returns if a given value represents an array type.
@@ -6891,7 +6923,7 @@ var Union = /** @class */ (function (_super) {
6891
6923
  configurable: true,
6892
6924
  writable: true,
6893
6925
  value: function (current, newValue, parent, subpath) {
6894
- var type = this.determineType(newValue, current.type);
6926
+ var type = this.determineType(newValue, current.getReconciliationType());
6895
6927
  if (!type)
6896
6928
  throw fail$1("No matching type for union " + this.describe()); // can happen in prod builds
6897
6929
  return type.reconcile(current, newValue, parent, subpath);