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.
|
@@ -1126,6 +1126,14 @@ var BaseNode = /** @class */ (function () {
|
|
|
1126
1126
|
enumerable: false,
|
|
1127
1127
|
configurable: true
|
|
1128
1128
|
});
|
|
1129
|
+
Object.defineProperty(BaseNode.prototype, "getReconciliationType", {
|
|
1130
|
+
enumerable: false,
|
|
1131
|
+
configurable: true,
|
|
1132
|
+
writable: true,
|
|
1133
|
+
value: function () {
|
|
1134
|
+
return this.type;
|
|
1135
|
+
}
|
|
1136
|
+
});
|
|
1129
1137
|
Object.defineProperty(BaseNode.prototype, "baseSetParent", {
|
|
1130
1138
|
enumerable: false,
|
|
1131
1139
|
configurable: true,
|
|
@@ -4582,6 +4590,8 @@ function splitJsonPath(path) {
|
|
|
4582
4590
|
return parts;
|
|
4583
4591
|
}
|
|
4584
4592
|
|
|
4593
|
+
/** @hidden */
|
|
4594
|
+
var $preProcessorFailed = Symbol("$preProcessorFailed");
|
|
4585
4595
|
var SnapshotProcessor = /** @class */ (function (_super) {
|
|
4586
4596
|
__extends(SnapshotProcessor, _super);
|
|
4587
4597
|
function SnapshotProcessor(_subtype, _processors, name) {
|
|
@@ -4626,6 +4636,19 @@ var SnapshotProcessor = /** @class */ (function (_super) {
|
|
|
4626
4636
|
return sn;
|
|
4627
4637
|
}
|
|
4628
4638
|
});
|
|
4639
|
+
Object.defineProperty(SnapshotProcessor.prototype, "preProcessSnapshotSafe", {
|
|
4640
|
+
enumerable: false,
|
|
4641
|
+
configurable: true,
|
|
4642
|
+
writable: true,
|
|
4643
|
+
value: function (sn) {
|
|
4644
|
+
try {
|
|
4645
|
+
return this.preProcessSnapshot(sn);
|
|
4646
|
+
}
|
|
4647
|
+
catch (e) {
|
|
4648
|
+
return $preProcessorFailed;
|
|
4649
|
+
}
|
|
4650
|
+
}
|
|
4651
|
+
});
|
|
4629
4652
|
Object.defineProperty(SnapshotProcessor.prototype, "postProcessSnapshot", {
|
|
4630
4653
|
enumerable: false,
|
|
4631
4654
|
configurable: true,
|
|
@@ -4649,6 +4672,9 @@ var SnapshotProcessor = /** @class */ (function (_super) {
|
|
|
4649
4672
|
node.getSnapshot = function () {
|
|
4650
4673
|
return _this.postProcessSnapshot(oldGetSnapshot.call(node));
|
|
4651
4674
|
};
|
|
4675
|
+
node.getReconciliationType = function () {
|
|
4676
|
+
return _this;
|
|
4677
|
+
};
|
|
4652
4678
|
}
|
|
4653
4679
|
});
|
|
4654
4680
|
Object.defineProperty(SnapshotProcessor.prototype, "instantiate", {
|
|
@@ -4691,7 +4717,10 @@ var SnapshotProcessor = /** @class */ (function (_super) {
|
|
|
4691
4717
|
configurable: true,
|
|
4692
4718
|
writable: true,
|
|
4693
4719
|
value: function (value, context) {
|
|
4694
|
-
var processedSn = this.
|
|
4720
|
+
var processedSn = this.preProcessSnapshotSafe(value);
|
|
4721
|
+
if (processedSn === $preProcessorFailed) {
|
|
4722
|
+
return typeCheckFailure(context, value, "Failed to preprocess value");
|
|
4723
|
+
}
|
|
4695
4724
|
return this._subtype.validate(processedSn, context);
|
|
4696
4725
|
}
|
|
4697
4726
|
});
|
|
@@ -4712,7 +4741,10 @@ var SnapshotProcessor = /** @class */ (function (_super) {
|
|
|
4712
4741
|
? this._subtype
|
|
4713
4742
|
: isStateTreeNode(thing)
|
|
4714
4743
|
? getSnapshot(thing, false)
|
|
4715
|
-
: this.
|
|
4744
|
+
: this.preProcessSnapshotSafe(thing);
|
|
4745
|
+
if (value === $preProcessorFailed) {
|
|
4746
|
+
return false;
|
|
4747
|
+
}
|
|
4716
4748
|
return this._subtype.validate(value, [{ path: "", type: this._subtype }]).length === 0;
|
|
4717
4749
|
}
|
|
4718
4750
|
});
|
|
@@ -5732,8 +5764,8 @@ function areSame(oldNode, newValue) {
|
|
|
5732
5764
|
oldNode.identifier !== null &&
|
|
5733
5765
|
oldNode.identifierAttribute &&
|
|
5734
5766
|
isPlainObject(newValue) &&
|
|
5735
|
-
oldNode.type.
|
|
5736
|
-
oldNode.type.
|
|
5767
|
+
oldNode.type.is(newValue) &&
|
|
5768
|
+
oldNode.type.isMatchingSnapshotId(oldNode, newValue));
|
|
5737
5769
|
}
|
|
5738
5770
|
/**
|
|
5739
5771
|
* Returns if a given value represents an array type.
|
|
@@ -6887,7 +6919,7 @@ var Union = /** @class */ (function (_super) {
|
|
|
6887
6919
|
configurable: true,
|
|
6888
6920
|
writable: true,
|
|
6889
6921
|
value: function (current, newValue, parent, subpath) {
|
|
6890
|
-
var type = this.determineType(newValue, current.
|
|
6922
|
+
var type = this.determineType(newValue, current.getReconciliationType());
|
|
6891
6923
|
if (!type)
|
|
6892
6924
|
throw fail$1("No matching type for union " + this.describe()); // can happen in prod builds
|
|
6893
6925
|
return type.reconcile(current, newValue, parent, subpath);
|
|
@@ -1130,6 +1130,14 @@
|
|
|
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,
|
|
@@ -4564,6 +4572,8 @@
|
|
|
4564
4572
|
return parts;
|
|
4565
4573
|
}
|
|
4566
4574
|
|
|
4575
|
+
/** @hidden */
|
|
4576
|
+
var $preProcessorFailed = Symbol("$preProcessorFailed");
|
|
4567
4577
|
var SnapshotProcessor = /** @class */ (function (_super) {
|
|
4568
4578
|
__extends(SnapshotProcessor, _super);
|
|
4569
4579
|
function SnapshotProcessor(_subtype, _processors, name) {
|
|
@@ -4608,6 +4618,19 @@
|
|
|
4608
4618
|
return sn;
|
|
4609
4619
|
}
|
|
4610
4620
|
});
|
|
4621
|
+
Object.defineProperty(SnapshotProcessor.prototype, "preProcessSnapshotSafe", {
|
|
4622
|
+
enumerable: false,
|
|
4623
|
+
configurable: true,
|
|
4624
|
+
writable: true,
|
|
4625
|
+
value: function (sn) {
|
|
4626
|
+
try {
|
|
4627
|
+
return this.preProcessSnapshot(sn);
|
|
4628
|
+
}
|
|
4629
|
+
catch (e) {
|
|
4630
|
+
return $preProcessorFailed;
|
|
4631
|
+
}
|
|
4632
|
+
}
|
|
4633
|
+
});
|
|
4611
4634
|
Object.defineProperty(SnapshotProcessor.prototype, "postProcessSnapshot", {
|
|
4612
4635
|
enumerable: false,
|
|
4613
4636
|
configurable: true,
|
|
@@ -4631,6 +4654,9 @@
|
|
|
4631
4654
|
node.getSnapshot = function () {
|
|
4632
4655
|
return _this.postProcessSnapshot(oldGetSnapshot.call(node));
|
|
4633
4656
|
};
|
|
4657
|
+
node.getReconciliationType = function () {
|
|
4658
|
+
return _this;
|
|
4659
|
+
};
|
|
4634
4660
|
}
|
|
4635
4661
|
});
|
|
4636
4662
|
Object.defineProperty(SnapshotProcessor.prototype, "instantiate", {
|
|
@@ -4673,7 +4699,10 @@
|
|
|
4673
4699
|
configurable: true,
|
|
4674
4700
|
writable: true,
|
|
4675
4701
|
value: function (value, context) {
|
|
4676
|
-
var processedSn = this.
|
|
4702
|
+
var processedSn = this.preProcessSnapshotSafe(value);
|
|
4703
|
+
if (processedSn === $preProcessorFailed) {
|
|
4704
|
+
return typeCheckFailure(context, value, "Failed to preprocess value");
|
|
4705
|
+
}
|
|
4677
4706
|
return this._subtype.validate(processedSn, context);
|
|
4678
4707
|
}
|
|
4679
4708
|
});
|
|
@@ -4694,7 +4723,10 @@
|
|
|
4694
4723
|
? this._subtype
|
|
4695
4724
|
: isStateTreeNode(thing)
|
|
4696
4725
|
? getSnapshot(thing, false)
|
|
4697
|
-
: this.
|
|
4726
|
+
: this.preProcessSnapshotSafe(thing);
|
|
4727
|
+
if (value === $preProcessorFailed) {
|
|
4728
|
+
return false;
|
|
4729
|
+
}
|
|
4698
4730
|
return this._subtype.validate(value, [{ path: "", type: this._subtype }]).length === 0;
|
|
4699
4731
|
}
|
|
4700
4732
|
});
|
|
@@ -5714,8 +5746,8 @@
|
|
|
5714
5746
|
oldNode.identifier !== null &&
|
|
5715
5747
|
oldNode.identifierAttribute &&
|
|
5716
5748
|
isPlainObject(newValue) &&
|
|
5717
|
-
oldNode.type.
|
|
5718
|
-
oldNode.type.
|
|
5749
|
+
oldNode.type.is(newValue) &&
|
|
5750
|
+
oldNode.type.isMatchingSnapshotId(oldNode, newValue));
|
|
5719
5751
|
}
|
|
5720
5752
|
/**
|
|
5721
5753
|
* Returns if a given value represents an array type.
|
|
@@ -6869,7 +6901,7 @@
|
|
|
6869
6901
|
configurable: true,
|
|
6870
6902
|
writable: true,
|
|
6871
6903
|
value: function (current, newValue, parent, subpath) {
|
|
6872
|
-
var type = this.determineType(newValue, current.
|
|
6904
|
+
var type = this.determineType(newValue, current.getReconciliationType());
|
|
6873
6905
|
if (!type)
|
|
6874
6906
|
throw fail$1("No matching type for union " + this.describe()); // can happen in prod builds
|
|
6875
6907
|
return type.reconcile(current, newValue, parent, subpath);
|