mobx-state-tree 5.0.3 → 5.1.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.
- package/README.md +1 -1
- package/dist/core/flow.d.ts +3 -3
- package/dist/mobx-state-tree.js +59 -26
- package/dist/mobx-state-tree.min.js +1 -1
- package/dist/mobx-state-tree.module.js +59 -26
- package/dist/mobx-state-tree.umd.js +59 -26
- package/dist/mobx-state-tree.umd.min.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
[](https://badge.fury.io/js/mobx-state-tree)
|
|
6
6
|
[](https://circleci.com/gh/mobxjs/mobx-state-tree)
|
|
7
|
-
[](https://codecov.io/gh/mobxjs/mobx-state-tree)
|
|
8
8
|
[](https://github.com/mobxjs/mobx-state-tree/discussions)
|
|
9
9
|
|
|
10
10
|
## What is mobx-state-tree?
|
package/dist/core/flow.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @hidden
|
|
3
3
|
*/
|
|
4
|
-
export declare type FlowReturn<R> = R extends
|
|
4
|
+
export declare type FlowReturn<R> = R extends PromiseLike<infer T> ? T : R;
|
|
5
5
|
/**
|
|
6
6
|
* See [asynchronous actions](concepts/async-actions.md).
|
|
7
7
|
*
|
|
8
8
|
* @returns The flow as a promise.
|
|
9
9
|
*/
|
|
10
|
-
export declare function flow<R, Args extends any[]>(generator: (...args: Args) => Generator<
|
|
10
|
+
export declare function flow<R, Args extends any[]>(generator: (...args: Args) => Generator<PromiseLike<any>, R, any>): (...args: Args) => PromiseLike<FlowReturn<R>>;
|
|
11
11
|
/**
|
|
12
12
|
* @deprecated Not needed since TS3.6.
|
|
13
13
|
* Used for TypeScript to make flows that return a promise return the actual promise result.
|
|
@@ -38,7 +38,7 @@ export declare function castFlowReturn<T>(val: T): T;
|
|
|
38
38
|
* }))
|
|
39
39
|
* ```
|
|
40
40
|
*/
|
|
41
|
-
export declare function toGeneratorFunction<R, Args extends any[]>(p: (...args: Args) =>
|
|
41
|
+
export declare function toGeneratorFunction<R, Args extends any[]>(p: (...args: Args) => PromiseLike<R>): (...args: Args) => Generator<PromiseLike<R>, R, R>;
|
|
42
42
|
/**
|
|
43
43
|
* @experimental
|
|
44
44
|
* experimental api - might change on minor/patch releases
|
package/dist/mobx-state-tree.js
CHANGED
|
@@ -580,7 +580,7 @@ function resolveIdentifier(type, target, identifier) {
|
|
|
580
580
|
assertIsStateTreeNode(target, 2);
|
|
581
581
|
assertIsValidIdentifier(identifier, 3);
|
|
582
582
|
var node = getStateTreeNode(target).root.identifierCache.resolve(type, normalizeIdentifier(identifier));
|
|
583
|
-
return node ? node.value
|
|
583
|
+
return node === null || node === void 0 ? void 0 : node.value;
|
|
584
584
|
}
|
|
585
585
|
/**
|
|
586
586
|
* Returns the identifier of the target node.
|
|
@@ -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,
|
|
@@ -3922,14 +3930,12 @@ function isMutable(value) {
|
|
|
3922
3930
|
*/
|
|
3923
3931
|
function isPrimitive(value, includeDate) {
|
|
3924
3932
|
if (includeDate === void 0) { includeDate = true; }
|
|
3925
|
-
|
|
3926
|
-
|
|
3927
|
-
|
|
3933
|
+
return (value === null ||
|
|
3934
|
+
value === undefined ||
|
|
3935
|
+
typeof value === "string" ||
|
|
3928
3936
|
typeof value === "number" ||
|
|
3929
3937
|
typeof value === "boolean" ||
|
|
3930
|
-
(includeDate && value instanceof Date))
|
|
3931
|
-
return true;
|
|
3932
|
-
return false;
|
|
3938
|
+
(includeDate && value instanceof Date));
|
|
3933
3939
|
}
|
|
3934
3940
|
/**
|
|
3935
3941
|
* @internal
|
|
@@ -4586,6 +4592,8 @@ function splitJsonPath(path) {
|
|
|
4586
4592
|
return parts;
|
|
4587
4593
|
}
|
|
4588
4594
|
|
|
4595
|
+
/** @hidden */
|
|
4596
|
+
var $preProcessorFailed = Symbol("$preProcessorFailed");
|
|
4589
4597
|
var SnapshotProcessor = /** @class */ (function (_super) {
|
|
4590
4598
|
__extends(SnapshotProcessor, _super);
|
|
4591
4599
|
function SnapshotProcessor(_subtype, _processors, name) {
|
|
@@ -4630,6 +4638,19 @@ var SnapshotProcessor = /** @class */ (function (_super) {
|
|
|
4630
4638
|
return sn;
|
|
4631
4639
|
}
|
|
4632
4640
|
});
|
|
4641
|
+
Object.defineProperty(SnapshotProcessor.prototype, "preProcessSnapshotSafe", {
|
|
4642
|
+
enumerable: false,
|
|
4643
|
+
configurable: true,
|
|
4644
|
+
writable: true,
|
|
4645
|
+
value: function (sn) {
|
|
4646
|
+
try {
|
|
4647
|
+
return this.preProcessSnapshot(sn);
|
|
4648
|
+
}
|
|
4649
|
+
catch (e) {
|
|
4650
|
+
return $preProcessorFailed;
|
|
4651
|
+
}
|
|
4652
|
+
}
|
|
4653
|
+
});
|
|
4633
4654
|
Object.defineProperty(SnapshotProcessor.prototype, "postProcessSnapshot", {
|
|
4634
4655
|
enumerable: false,
|
|
4635
4656
|
configurable: true,
|
|
@@ -4648,11 +4669,14 @@ var SnapshotProcessor = /** @class */ (function (_super) {
|
|
|
4648
4669
|
value: function (node) {
|
|
4649
4670
|
var _this = this;
|
|
4650
4671
|
// the node has to use these methods rather than the original type ones
|
|
4651
|
-
proxyNodeTypeMethods(node.type, this, "create"
|
|
4672
|
+
proxyNodeTypeMethods(node.type, this, "create");
|
|
4652
4673
|
var oldGetSnapshot = node.getSnapshot;
|
|
4653
4674
|
node.getSnapshot = function () {
|
|
4654
4675
|
return _this.postProcessSnapshot(oldGetSnapshot.call(node));
|
|
4655
4676
|
};
|
|
4677
|
+
node.getReconciliationType = function () {
|
|
4678
|
+
return _this;
|
|
4679
|
+
};
|
|
4656
4680
|
}
|
|
4657
4681
|
});
|
|
4658
4682
|
Object.defineProperty(SnapshotProcessor.prototype, "instantiate", {
|
|
@@ -4695,7 +4719,10 @@ var SnapshotProcessor = /** @class */ (function (_super) {
|
|
|
4695
4719
|
configurable: true,
|
|
4696
4720
|
writable: true,
|
|
4697
4721
|
value: function (value, context) {
|
|
4698
|
-
var processedSn = this.
|
|
4722
|
+
var processedSn = this.preProcessSnapshotSafe(value);
|
|
4723
|
+
if (processedSn === $preProcessorFailed) {
|
|
4724
|
+
return typeCheckFailure(context, value, "Failed to preprocess value");
|
|
4725
|
+
}
|
|
4699
4726
|
return this._subtype.validate(processedSn, context);
|
|
4700
4727
|
}
|
|
4701
4728
|
});
|
|
@@ -4716,7 +4743,10 @@ var SnapshotProcessor = /** @class */ (function (_super) {
|
|
|
4716
4743
|
? this._subtype
|
|
4717
4744
|
: isStateTreeNode(thing)
|
|
4718
4745
|
? getSnapshot(thing, false)
|
|
4719
|
-
: this.
|
|
4746
|
+
: this.preProcessSnapshotSafe(thing);
|
|
4747
|
+
if (value === $preProcessorFailed) {
|
|
4748
|
+
return false;
|
|
4749
|
+
}
|
|
4720
4750
|
return this._subtype.validate(value, [{ path: "", type: this._subtype }]).length === 0;
|
|
4721
4751
|
}
|
|
4722
4752
|
});
|
|
@@ -4737,7 +4767,7 @@ var SnapshotProcessor = /** @class */ (function (_super) {
|
|
|
4737
4767
|
return false;
|
|
4738
4768
|
}
|
|
4739
4769
|
var processedSn = this.preProcessSnapshot(snapshot);
|
|
4740
|
-
return
|
|
4770
|
+
return this._subtype.isMatchingSnapshotId(current, processedSn);
|
|
4741
4771
|
}
|
|
4742
4772
|
});
|
|
4743
4773
|
return SnapshotProcessor;
|
|
@@ -5001,18 +5031,17 @@ var MapType = /** @class */ (function (_super) {
|
|
|
5001
5031
|
}
|
|
5002
5032
|
var modelTypes = [];
|
|
5003
5033
|
if (tryCollectModelTypes(this._subType, modelTypes)) {
|
|
5004
|
-
var
|
|
5005
|
-
|
|
5006
|
-
|
|
5007
|
-
|
|
5008
|
-
|
|
5009
|
-
}
|
|
5010
|
-
identifierAttribute_1 = type.identifierAttribute;
|
|
5034
|
+
var identifierAttribute = modelTypes.reduce(function (current, type) {
|
|
5035
|
+
if (!type.identifierAttribute)
|
|
5036
|
+
return current;
|
|
5037
|
+
if (current && current !== type.identifierAttribute) {
|
|
5038
|
+
throw fail$1("The objects in a map should all have the same identifier attribute, expected '" + current + "', but child of type '" + type.name + "' declared attribute '" + type.identifierAttribute + "' as identifier");
|
|
5011
5039
|
}
|
|
5012
|
-
|
|
5013
|
-
|
|
5040
|
+
return type.identifierAttribute;
|
|
5041
|
+
}, undefined);
|
|
5042
|
+
if (identifierAttribute) {
|
|
5014
5043
|
this.identifierMode = MapIdentifierMode.YES;
|
|
5015
|
-
this.mapIdentifierAttribute =
|
|
5044
|
+
this.mapIdentifierAttribute = identifierAttribute;
|
|
5016
5045
|
}
|
|
5017
5046
|
else {
|
|
5018
5047
|
this.identifierMode = MapIdentifierMode.NO;
|
|
@@ -5731,13 +5760,17 @@ function areSame(oldNode, newValue) {
|
|
|
5731
5760
|
if (oldNode.snapshot === newValue) {
|
|
5732
5761
|
return true;
|
|
5733
5762
|
}
|
|
5763
|
+
// Non object nodes don't get reconciled
|
|
5764
|
+
if (!(oldNode instanceof ObjectNode)) {
|
|
5765
|
+
return false;
|
|
5766
|
+
}
|
|
5767
|
+
var oldNodeType = oldNode.getReconciliationType();
|
|
5734
5768
|
// new value is a snapshot with the correct identifier
|
|
5735
|
-
return (oldNode
|
|
5736
|
-
oldNode.identifier !== null &&
|
|
5769
|
+
return (oldNode.identifier !== null &&
|
|
5737
5770
|
oldNode.identifierAttribute &&
|
|
5738
5771
|
isPlainObject(newValue) &&
|
|
5739
|
-
|
|
5740
|
-
|
|
5772
|
+
oldNodeType.is(newValue) &&
|
|
5773
|
+
oldNodeType.isMatchingSnapshotId(oldNode, newValue));
|
|
5741
5774
|
}
|
|
5742
5775
|
/**
|
|
5743
5776
|
* Returns if a given value represents an array type.
|
|
@@ -6891,7 +6924,7 @@ var Union = /** @class */ (function (_super) {
|
|
|
6891
6924
|
configurable: true,
|
|
6892
6925
|
writable: true,
|
|
6893
6926
|
value: function (current, newValue, parent, subpath) {
|
|
6894
|
-
var type = this.determineType(newValue, current.
|
|
6927
|
+
var type = this.determineType(newValue, current.getReconciliationType());
|
|
6895
6928
|
if (!type)
|
|
6896
6929
|
throw fail$1("No matching type for union " + this.describe()); // can happen in prod builds
|
|
6897
6930
|
return type.reconcile(current, newValue, parent, subpath);
|