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.
package/dist/mobx-state-tree.js
CHANGED
|
@@ -63,7 +63,7 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
|
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 @@ function __rest(s, e) {
|
|
|
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 =
|
|
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 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
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 &&
|
|
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 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
1825
1827
|
value: function (name) {
|
|
1826
1828
|
var _this = this;
|
|
1827
1829
|
this.fireInternalHook(name);
|
|
1828
|
-
var fn = this.storedValue &&
|
|
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 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
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)) ||
|
|
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 @@ var ComplexType = /** @class */ (function (_super) {
|
|
|
2565
2570
|
writable: true,
|
|
2566
2571
|
value: function (current, snapshot) {
|
|
2567
2572
|
return (!current.identifierAttribute ||
|
|
2568
|
-
current.identifier ===
|
|
2573
|
+
current.identifier ===
|
|
2574
|
+
normalizeIdentifier(snapshot[current.identifierAttribute]));
|
|
2569
2575
|
}
|
|
2570
2576
|
});
|
|
2571
2577
|
Object.defineProperty(ComplexType.prototype, "tryToReconcileNode", {
|
|
@@ -2963,7 +2969,8 @@ function serializeArgument(node, actionName, index, arg) {
|
|
|
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) ||
|
|
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 @@ function createActionInvoker(target, name, fn) {
|
|
|
3219
3226
|
tree: getRoot(target),
|
|
3220
3227
|
rootId: parentContext ? parentContext.rootId : id,
|
|
3221
3228
|
parentId: parentContext ? parentContext.id : 0,
|
|
3222
|
-
allParentIds: parentContext
|
|
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 @@ function getRelativePathBetweenNodes(base, target) {
|
|
|
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
|
|
@@ -4061,7 +4069,8 @@ function deepFreeze(value) {
|
|
|
4061
4069
|
freeze(value);
|
|
4062
4070
|
if (isPlainObject(value)) {
|
|
4063
4071
|
Object.keys(value).forEach(function (propKey) {
|
|
4064
|
-
if (!isPrimitive(value[propKey]) &&
|
|
4072
|
+
if (!isPrimitive(value[propKey]) &&
|
|
4073
|
+
!Object.isFrozen(value[propKey])) {
|
|
4065
4074
|
deepFreeze(value[propKey]);
|
|
4066
4075
|
}
|
|
4067
4076
|
});
|
|
@@ -6988,7 +6997,9 @@ function refinement() {
|
|
|
6988
6997
|
var name = typeof args[0] === "string" ? args.shift() : isType(args[0]) ? args[0].name : null;
|
|
6989
6998
|
var type = args[0];
|
|
6990
6999
|
var predicate = args[1];
|
|
6991
|
-
var message = args[2]
|
|
7000
|
+
var message = args[2]
|
|
7001
|
+
? args[2]
|
|
7002
|
+
: function (v) { return "Value does not respect the refinement predicate"; };
|
|
6992
7003
|
// ensures all parameters are correct
|
|
6993
7004
|
assertIsType(type, [1, 2]);
|
|
6994
7005
|
assertIsString(name, 1);
|
|
@@ -7610,7 +7621,8 @@ var Lazy = /** @class */ (function (_super) {
|
|
|
7610
7621
|
mobx.when(function () {
|
|
7611
7622
|
return _this.pendingNodeList.length > 0 &&
|
|
7612
7623
|
_this.pendingNodeList.some(function (node) {
|
|
7613
|
-
return node.isAlive &&
|
|
7624
|
+
return node.isAlive &&
|
|
7625
|
+
_this.options.shouldLoadPredicate(node.parent ? node.parent.value : null);
|
|
7614
7626
|
});
|
|
7615
7627
|
}, function () {
|
|
7616
7628
|
_this.options.loadType().then(mobx.action(function (type) {
|
|
@@ -8124,7 +8136,9 @@ var IdentifierReferenceType = /** @class */ (function (_super) {
|
|
|
8124
8136
|
configurable: true,
|
|
8125
8137
|
writable: true,
|
|
8126
8138
|
value: function (parent, subpath, environment, initialValue) {
|
|
8127
|
-
var identifier = isStateTreeNode(initialValue)
|
|
8139
|
+
var identifier = isStateTreeNode(initialValue)
|
|
8140
|
+
? getIdentifier(initialValue)
|
|
8141
|
+
: initialValue;
|
|
8128
8142
|
var storedRef = new StoredReference(initialValue, this.targetType);
|
|
8129
8143
|
var storedRefNode = createScalarNode(this, parent, subpath, environment, storedRef);
|
|
8130
8144
|
storedRef.node = storedRefNode;
|
|
@@ -8209,7 +8223,9 @@ var CustomReferenceType = /** @class */ (function (_super) {
|
|
|
8209
8223
|
var newIdentifier = isStateTreeNode(newValue)
|
|
8210
8224
|
? this.options.set(newValue, current ? current.storedValue : null)
|
|
8211
8225
|
: newValue;
|
|
8212
|
-
if (!current.isDetaching &&
|
|
8226
|
+
if (!current.isDetaching &&
|
|
8227
|
+
current.type === this &&
|
|
8228
|
+
current.storedValue === newIdentifier) {
|
|
8213
8229
|
current.setParent(parent, subpath);
|
|
8214
8230
|
return current;
|
|
8215
8231
|
}
|