mobx-state-tree 5.4.0-pre.1 → 5.4.0
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.
- package/dist/mobx-state-tree.js +20 -8
- package/dist/mobx-state-tree.min.js +1 -1
- package/dist/mobx-state-tree.module.js +20 -8
- package/dist/mobx-state-tree.umd.js +20 -8
- package/dist/mobx-state-tree.umd.min.js +1 -1
- package/dist/types/utility-types/snapshotProcessor.d.ts +9 -7
- package/package.json +1 -2
package/dist/mobx-state-tree.js
CHANGED
|
@@ -1462,6 +1462,12 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
1462
1462
|
writable: true,
|
|
1463
1463
|
value: void 0
|
|
1464
1464
|
});
|
|
1465
|
+
Object.defineProperty(_this, "hasSnapshotPostProcessor", {
|
|
1466
|
+
enumerable: true,
|
|
1467
|
+
configurable: true,
|
|
1468
|
+
writable: true,
|
|
1469
|
+
value: false
|
|
1470
|
+
});
|
|
1465
1471
|
Object.defineProperty(_this, "_applyPatches", {
|
|
1466
1472
|
enumerable: true,
|
|
1467
1473
|
configurable: true,
|
|
@@ -1792,6 +1798,9 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
1792
1798
|
Object.defineProperty(ObjectNode.prototype, "snapshot", {
|
|
1793
1799
|
// advantage of using computed for a snapshot is that nicely respects transactions etc.
|
|
1794
1800
|
get: function () {
|
|
1801
|
+
if (this.hasSnapshotPostProcessor) {
|
|
1802
|
+
this.createObservableInstanceIfNeeded();
|
|
1803
|
+
}
|
|
1795
1804
|
return this._snapshotComputed.get();
|
|
1796
1805
|
},
|
|
1797
1806
|
enumerable: false,
|
|
@@ -4704,9 +4713,9 @@ var SnapshotProcessor = /** @class */ (function (_super) {
|
|
|
4704
4713
|
enumerable: false,
|
|
4705
4714
|
configurable: true,
|
|
4706
4715
|
writable: true,
|
|
4707
|
-
value: function (sn) {
|
|
4716
|
+
value: function (sn, node) {
|
|
4708
4717
|
if (this._processors.postProcessor) {
|
|
4709
|
-
return this._processors.postProcessor.call(null, sn);
|
|
4718
|
+
return this._processors.postProcessor.call(null, sn, node.storedValue);
|
|
4710
4719
|
}
|
|
4711
4720
|
return sn;
|
|
4712
4721
|
}
|
|
@@ -4719,10 +4728,11 @@ var SnapshotProcessor = /** @class */ (function (_super) {
|
|
|
4719
4728
|
var _this = this;
|
|
4720
4729
|
// the node has to use these methods rather than the original type ones
|
|
4721
4730
|
proxyNodeTypeMethods(node.type, this, "create");
|
|
4731
|
+
if (node instanceof ObjectNode) {
|
|
4732
|
+
node.hasSnapshotPostProcessor = !!this._processors.postProcessor;
|
|
4733
|
+
}
|
|
4722
4734
|
var oldGetSnapshot = node.getSnapshot;
|
|
4723
|
-
node.getSnapshot = function () {
|
|
4724
|
-
return _this.postProcessSnapshot(oldGetSnapshot.call(node));
|
|
4725
|
-
};
|
|
4735
|
+
node.getSnapshot = function () { return _this.postProcessSnapshot(oldGetSnapshot.call(node), node); };
|
|
4726
4736
|
if (!isUnionType(this._subtype)) {
|
|
4727
4737
|
node.getReconciliationType = function () {
|
|
4728
4738
|
return _this;
|
|
@@ -4762,7 +4772,7 @@ var SnapshotProcessor = /** @class */ (function (_super) {
|
|
|
4762
4772
|
value: function (node, applyPostProcess) {
|
|
4763
4773
|
if (applyPostProcess === void 0) { applyPostProcess = true; }
|
|
4764
4774
|
var sn = this._subtype.getSnapshot(node);
|
|
4765
|
-
return applyPostProcess ? this.postProcessSnapshot(sn) : sn;
|
|
4775
|
+
return applyPostProcess ? this.postProcessSnapshot(sn, node) : sn;
|
|
4766
4776
|
}
|
|
4767
4777
|
});
|
|
4768
4778
|
Object.defineProperty(SnapshotProcessor.prototype, "isValidSnapshot", {
|
|
@@ -4853,15 +4863,17 @@ function proxyNodeTypeMethods(nodeType, snapshotProcessorType) {
|
|
|
4853
4863
|
* interface BackendTodo {
|
|
4854
4864
|
* text: string | null
|
|
4855
4865
|
* }
|
|
4866
|
+
*
|
|
4856
4867
|
* const Todo2 = types.snapshotProcessor(Todo1, {
|
|
4857
4868
|
* // from snapshot to instance
|
|
4858
|
-
* preProcessor(
|
|
4869
|
+
* preProcessor(snapshot: BackendTodo) {
|
|
4859
4870
|
* return {
|
|
4860
4871
|
* text: sn.text || "";
|
|
4861
4872
|
* }
|
|
4862
4873
|
* },
|
|
4874
|
+
*
|
|
4863
4875
|
* // from instance to snapshot
|
|
4864
|
-
* postProcessor(
|
|
4876
|
+
* postProcessor(snapshot, node): BackendTodo {
|
|
4865
4877
|
* return {
|
|
4866
4878
|
* text: !sn.text ? null : sn.text
|
|
4867
4879
|
* }
|