mobx-state-tree 5.4.2-pre.1 → 5.4.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/core/action.d.ts +2 -2
- package/dist/core/flow.d.ts +1 -1
- package/dist/core/mst-operations.d.ts +1 -1
- package/dist/core/node/Hook.d.ts +1 -1
- package/dist/core/node/livelinessChecking.d.ts +2 -2
- package/dist/core/node/node-utils.d.ts +1 -1
- package/dist/core/type/type-checker.d.ts +2 -2
- package/dist/core/type/type.d.ts +8 -8
- package/dist/mobx-state-tree.js +118 -122
- package/dist/mobx-state-tree.min.js +16 -1
- package/dist/mobx-state-tree.module.js +118 -122
- package/dist/mobx-state-tree.umd.js +120 -124
- package/dist/mobx-state-tree.umd.min.js +16 -1
- package/dist/types/complex-types/model.d.ts +25 -20
- package/dist/types/utility-types/enumeration.d.ts +3 -3
- package/dist/types/utility-types/identifier.d.ts +1 -1
- package/dist/types/utility-types/optional.d.ts +3 -3
- package/dist/types/utility-types/reference.d.ts +4 -4
- package/dist/types/utility-types/snapshotProcessor.d.ts +1 -1
- package/dist/types/utility-types/union.d.ts +37 -7
- package/dist/utils.d.ts +1 -1
- package/package.json +14 -14
package/dist/mobx-state-tree.js
CHANGED
|
@@ -49,7 +49,7 @@ var Hook;
|
|
|
49
49
|
Hook["beforeDestroy"] = "beforeDestroy";
|
|
50
50
|
})(Hook || (Hook = {}));
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
/*! *****************************************************************************
|
|
53
53
|
Copyright (c) Microsoft Corporation.
|
|
54
54
|
|
|
55
55
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
@@ -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
|
|
66
|
+
/* global Reflect, Promise */
|
|
67
67
|
|
|
68
68
|
var extendStatics = function(d, b) {
|
|
69
69
|
extendStatics = Object.setPrototypeOf ||
|
|
@@ -109,7 +109,7 @@ function __generator(thisArg, body) {
|
|
|
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.");
|
|
112
|
-
while (
|
|
112
|
+
while (_) try {
|
|
113
113
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
114
114
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
115
115
|
switch (op[0]) {
|
|
@@ -160,20 +160,12 @@ function __read(o, n) {
|
|
|
160
160
|
return ar;
|
|
161
161
|
}
|
|
162
162
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
}
|
|
170
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
174
|
-
var e = new Error(message);
|
|
175
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
176
|
-
};
|
|
163
|
+
/** @deprecated */
|
|
164
|
+
function __spread() {
|
|
165
|
+
for (var ar = [], i = 0; i < arguments.length; i++)
|
|
166
|
+
ar = ar.concat(__read(arguments[i]));
|
|
167
|
+
return ar;
|
|
168
|
+
}
|
|
177
169
|
|
|
178
170
|
/**
|
|
179
171
|
* Returns the _actual_ type of the given tree node. (Or throws)
|
|
@@ -471,7 +463,7 @@ function getParent(target, depth) {
|
|
|
471
463
|
return parent.storedValue;
|
|
472
464
|
parent = parent.parent;
|
|
473
465
|
}
|
|
474
|
-
throw fail("Failed to find the parent of "
|
|
466
|
+
throw fail("Failed to find the parent of " + getStateTreeNode(target) + " at depth " + depth);
|
|
475
467
|
}
|
|
476
468
|
/**
|
|
477
469
|
* Given a model instance, returns `true` if the object has a parent of given type, that is, is part of another object, map or array
|
|
@@ -509,7 +501,7 @@ function getParentOfType(target, type) {
|
|
|
509
501
|
return parent.storedValue;
|
|
510
502
|
parent = parent.parent;
|
|
511
503
|
}
|
|
512
|
-
throw fail("Failed to find the parent of "
|
|
504
|
+
throw fail("Failed to find the parent of " + getStateTreeNode(target) + " of a given type");
|
|
513
505
|
}
|
|
514
506
|
/**
|
|
515
507
|
* Given an object in a model tree, returns the root object of that tree.
|
|
@@ -877,14 +869,18 @@ function getMembers(target) {
|
|
|
877
869
|
reflected.volatile.push(key);
|
|
878
870
|
return;
|
|
879
871
|
}
|
|
880
|
-
if (descriptor.value.
|
|
881
|
-
reflected.actions.push(key);
|
|
882
|
-
if (descriptor.value._isFlowAction === true)
|
|
872
|
+
if (descriptor.value._isFlowAction === true) {
|
|
883
873
|
reflected.flowActions.push(key);
|
|
884
|
-
|
|
874
|
+
}
|
|
875
|
+
if (descriptor.value._isMSTAction === true) {
|
|
876
|
+
reflected.actions.push(key);
|
|
877
|
+
}
|
|
878
|
+
else if (mobx.isObservableProp(target, key)) {
|
|
885
879
|
reflected.volatile.push(key);
|
|
886
|
-
|
|
880
|
+
}
|
|
881
|
+
else {
|
|
887
882
|
reflected.views.push(key);
|
|
883
|
+
}
|
|
888
884
|
});
|
|
889
885
|
return reflected;
|
|
890
886
|
}
|
|
@@ -1364,7 +1360,7 @@ var ScalarNode = /** @class */ (function (_super) {
|
|
|
1364
1360
|
writable: true,
|
|
1365
1361
|
value: function () {
|
|
1366
1362
|
var path = (this.isAlive ? this.path : this.pathUponDeath) || "<root>";
|
|
1367
|
-
return
|
|
1363
|
+
return this.type.name + "@" + path + (this.isAlive ? "" : " [dead]");
|
|
1368
1364
|
}
|
|
1369
1365
|
});
|
|
1370
1366
|
Object.defineProperty(ScalarNode.prototype, "die", {
|
|
@@ -1510,7 +1506,7 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
1510
1506
|
enumerable: true,
|
|
1511
1507
|
configurable: true,
|
|
1512
1508
|
writable: true,
|
|
1513
|
-
value: 0 /*
|
|
1509
|
+
value: 0 /* UNINITIALIZED */
|
|
1514
1510
|
});
|
|
1515
1511
|
Object.defineProperty(_this, "_childNodes", {
|
|
1516
1512
|
enumerable: true,
|
|
@@ -1577,7 +1573,7 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
1577
1573
|
}
|
|
1578
1574
|
}
|
|
1579
1575
|
if (typeof id !== "string" && typeof id !== "number") {
|
|
1580
|
-
throw fail("Instance identifier '"
|
|
1576
|
+
throw fail("Instance identifier '" + _this.identifierAttribute + "' for type '" + _this.type.name + "' must be a string or a number");
|
|
1581
1577
|
}
|
|
1582
1578
|
// normalize internal identifier to string
|
|
1583
1579
|
_this.identifier = normalizeIdentifier(id);
|
|
@@ -1615,7 +1611,7 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
1615
1611
|
writable: true,
|
|
1616
1612
|
value: function (fireHooks) {
|
|
1617
1613
|
if (fireHooks === void 0) { fireHooks = true; }
|
|
1618
|
-
if (this._observableInstanceState === 0 /*
|
|
1614
|
+
if (this._observableInstanceState === 0 /* UNINITIALIZED */) {
|
|
1619
1615
|
this.createObservableInstance(fireHooks);
|
|
1620
1616
|
}
|
|
1621
1617
|
}
|
|
@@ -1633,7 +1629,7 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
1633
1629
|
throw fail("assertion failed: the creation of the observable instance must be done on the initializing phase");
|
|
1634
1630
|
}
|
|
1635
1631
|
}
|
|
1636
|
-
this._observableInstanceState = 1 /*
|
|
1632
|
+
this._observableInstanceState = 1 /* CREATING */;
|
|
1637
1633
|
// make sure the parent chain is created as well
|
|
1638
1634
|
// array with parent chain from parent to child
|
|
1639
1635
|
var parentChain = [];
|
|
@@ -1643,7 +1639,7 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
1643
1639
|
// this is done to avoid traversing the whole tree to the root when using
|
|
1644
1640
|
// the same reference again
|
|
1645
1641
|
while (parent &&
|
|
1646
|
-
parent._observableInstanceState === 0 /*
|
|
1642
|
+
parent._observableInstanceState === 0 /* UNINITIALIZED */) {
|
|
1647
1643
|
parentChain.unshift(parent);
|
|
1648
1644
|
parent = parent.parent;
|
|
1649
1645
|
}
|
|
@@ -1677,7 +1673,7 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
1677
1673
|
finally {
|
|
1678
1674
|
this._isRunningAction = false;
|
|
1679
1675
|
}
|
|
1680
|
-
this._observableInstanceState = 2 /*
|
|
1676
|
+
this._observableInstanceState = 2 /* CREATED */;
|
|
1681
1677
|
this._snapshotComputed.trackAndCompute();
|
|
1682
1678
|
if (this.isRoot)
|
|
1683
1679
|
this._addSnapshotReaction();
|
|
@@ -1760,10 +1756,10 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
1760
1756
|
throw fail("assertion failed: new parent expected");
|
|
1761
1757
|
}
|
|
1762
1758
|
if (this.parent && parentChanged) {
|
|
1763
|
-
throw fail("A node cannot exists twice in the state tree. Failed to add "
|
|
1759
|
+
throw fail("A node cannot exists twice in the state tree. Failed to add " + this + " to path '" + newParent.path + "/" + subpath + "'.");
|
|
1764
1760
|
}
|
|
1765
1761
|
if (!this.parent && newParent.root === this) {
|
|
1766
|
-
throw fail("A state tree is not allowed to contain itself. Cannot assign "
|
|
1762
|
+
throw fail("A state tree is not allowed to contain itself. Cannot assign " + this + " to path '" + newParent.path + "/" + subpath + "'");
|
|
1767
1763
|
}
|
|
1768
1764
|
if (!this.parent && !!this.environment && this.environment !== newParent.root.environment) {
|
|
1769
1765
|
throw fail("A state tree cannot be made part of another state tree as long as their environments are different.");
|
|
@@ -1822,7 +1818,7 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
1822
1818
|
value: function () {
|
|
1823
1819
|
if (!this.isAlive)
|
|
1824
1820
|
return this._snapshotUponDeath;
|
|
1825
|
-
return this._observableInstanceState === 2 /*
|
|
1821
|
+
return this._observableInstanceState === 2 /* CREATED */
|
|
1826
1822
|
? this._getActualSnapshot()
|
|
1827
1823
|
: this._getCachedInitialSnapshot();
|
|
1828
1824
|
}
|
|
@@ -1895,9 +1891,9 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
1895
1891
|
if (actionContext && actionContext.name != null) {
|
|
1896
1892
|
// try to use the context, and if it not available use the node one
|
|
1897
1893
|
var actionPath = (actionContext && actionContext.context && getPath(actionContext.context)) || escapedPath;
|
|
1898
|
-
actionFullPath =
|
|
1894
|
+
actionFullPath = actionPath + "." + actionContext.name + "()";
|
|
1899
1895
|
}
|
|
1900
|
-
return "You are trying to read or write to an object that is no longer part of a state tree. (Object type: '"
|
|
1896
|
+
return "You are trying to read or write to an object that is no longer part of a state tree. (Object type: '" + this.type.name + "', Path upon death: '" + escapedPath + "', Subpath: '" + subpath + "', Action: '" + actionFullPath + "'). Either detach nodes first, or don't use objects after removing / replacing them in the tree.";
|
|
1901
1897
|
}
|
|
1902
1898
|
});
|
|
1903
1899
|
Object.defineProperty(ObjectNode.prototype, "getChildNode", {
|
|
@@ -1910,7 +1906,7 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
1910
1906
|
});
|
|
1911
1907
|
this._autoUnbox = false;
|
|
1912
1908
|
try {
|
|
1913
|
-
return this._observableInstanceState === 2 /*
|
|
1909
|
+
return this._observableInstanceState === 2 /* CREATED */
|
|
1914
1910
|
? this.type.getChildNode(this, subpath)
|
|
1915
1911
|
: this._childNodes[subpath];
|
|
1916
1912
|
}
|
|
@@ -1927,7 +1923,7 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
1927
1923
|
this.assertAlive(EMPTY_OBJECT);
|
|
1928
1924
|
this._autoUnbox = false;
|
|
1929
1925
|
try {
|
|
1930
|
-
return this._observableInstanceState === 2 /*
|
|
1926
|
+
return this._observableInstanceState === 2 /* CREATED */
|
|
1931
1927
|
? this.type.getChildren(this)
|
|
1932
1928
|
: convertChildNodesToArray(this._childNodes);
|
|
1933
1929
|
}
|
|
@@ -1958,7 +1954,7 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
1958
1954
|
value: function (context) {
|
|
1959
1955
|
this.assertAlive(context);
|
|
1960
1956
|
if (!this.isRunningAction() && this.isProtected) {
|
|
1961
|
-
throw fail("Cannot modify '"
|
|
1957
|
+
throw fail("Cannot modify '" + this + "', the object is protected and can only be modified by using an action.");
|
|
1962
1958
|
}
|
|
1963
1959
|
}
|
|
1964
1960
|
});
|
|
@@ -1990,8 +1986,8 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
1990
1986
|
writable: true,
|
|
1991
1987
|
value: function () {
|
|
1992
1988
|
var path = (this.isAlive ? this.path : this.pathUponDeath) || "<root>";
|
|
1993
|
-
var identifier = this.identifier ? "(id: "
|
|
1994
|
-
return
|
|
1989
|
+
var identifier = this.identifier ? "(id: " + this.identifier + ")" : "";
|
|
1990
|
+
return this.type.name + "@" + path + identifier + (this.isAlive ? "" : " [dead]");
|
|
1995
1991
|
}
|
|
1996
1992
|
});
|
|
1997
1993
|
Object.defineProperty(ObjectNode.prototype, "finalizeCreation", {
|
|
@@ -2073,7 +2069,7 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
2073
2069
|
configurable: true,
|
|
2074
2070
|
writable: true,
|
|
2075
2071
|
value: function () {
|
|
2076
|
-
if (this._observableInstanceState === 0 /*
|
|
2072
|
+
if (this._observableInstanceState === 0 /* UNINITIALIZED */) {
|
|
2077
2073
|
return;
|
|
2078
2074
|
}
|
|
2079
2075
|
this.getChildren().forEach(function (node) {
|
|
@@ -2082,8 +2078,8 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
2082
2078
|
// beforeDestroy should run before the disposers since else we could end up in a situation where
|
|
2083
2079
|
// a disposer added with addDisposer at this stage (beforeDestroy) is actually never released
|
|
2084
2080
|
this.baseAboutToDie();
|
|
2085
|
-
this._internalEventsEmit("dispose" /*
|
|
2086
|
-
this._internalEventsClear("dispose" /*
|
|
2081
|
+
this._internalEventsEmit("dispose" /* Dispose */);
|
|
2082
|
+
this._internalEventsClear("dispose" /* Dispose */);
|
|
2087
2083
|
}
|
|
2088
2084
|
});
|
|
2089
2085
|
Object.defineProperty(ObjectNode.prototype, "finalizeDeath", {
|
|
@@ -2109,7 +2105,7 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
2109
2105
|
writable: true,
|
|
2110
2106
|
value: function (onChange) {
|
|
2111
2107
|
this._addSnapshotReaction();
|
|
2112
|
-
return this._internalEventsRegister("snapshot" /*
|
|
2108
|
+
return this._internalEventsRegister("snapshot" /* Snapshot */, onChange);
|
|
2113
2109
|
}
|
|
2114
2110
|
});
|
|
2115
2111
|
Object.defineProperty(ObjectNode.prototype, "emitSnapshot", {
|
|
@@ -2117,7 +2113,7 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
2117
2113
|
configurable: true,
|
|
2118
2114
|
writable: true,
|
|
2119
2115
|
value: function (snapshot) {
|
|
2120
|
-
this._internalEventsEmit("snapshot" /*
|
|
2116
|
+
this._internalEventsEmit("snapshot" /* Snapshot */, snapshot);
|
|
2121
2117
|
}
|
|
2122
2118
|
});
|
|
2123
2119
|
Object.defineProperty(ObjectNode.prototype, "onPatch", {
|
|
@@ -2125,7 +2121,7 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
2125
2121
|
configurable: true,
|
|
2126
2122
|
writable: true,
|
|
2127
2123
|
value: function (handler) {
|
|
2128
|
-
return this._internalEventsRegister("patch" /*
|
|
2124
|
+
return this._internalEventsRegister("patch" /* Patch */, handler);
|
|
2129
2125
|
}
|
|
2130
2126
|
});
|
|
2131
2127
|
Object.defineProperty(ObjectNode.prototype, "emitPatch", {
|
|
@@ -2133,12 +2129,12 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
2133
2129
|
configurable: true,
|
|
2134
2130
|
writable: true,
|
|
2135
2131
|
value: function (basePatch, source) {
|
|
2136
|
-
if (this._internalEventsHasSubscribers("patch" /*
|
|
2132
|
+
if (this._internalEventsHasSubscribers("patch" /* Patch */)) {
|
|
2137
2133
|
var localizedPatch = extend({}, basePatch, {
|
|
2138
2134
|
path: source.path.substr(this.path.length) + "/" + basePatch.path // calculate the relative path of the patch
|
|
2139
2135
|
});
|
|
2140
2136
|
var _a = __read(splitPatch(localizedPatch), 2), patch = _a[0], reversePatch = _a[1];
|
|
2141
|
-
this._internalEventsEmit("patch" /*
|
|
2137
|
+
this._internalEventsEmit("patch" /* Patch */, patch, reversePatch);
|
|
2142
2138
|
}
|
|
2143
2139
|
if (this.parent)
|
|
2144
2140
|
this.parent.emitPatch(basePatch, source);
|
|
@@ -2149,7 +2145,7 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
2149
2145
|
configurable: true,
|
|
2150
2146
|
writable: true,
|
|
2151
2147
|
value: function (disposer) {
|
|
2152
|
-
return this._internalEventsHas("dispose" /*
|
|
2148
|
+
return this._internalEventsHas("dispose" /* Dispose */, disposer);
|
|
2153
2149
|
}
|
|
2154
2150
|
});
|
|
2155
2151
|
Object.defineProperty(ObjectNode.prototype, "addDisposer", {
|
|
@@ -2158,7 +2154,7 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
2158
2154
|
writable: true,
|
|
2159
2155
|
value: function (disposer) {
|
|
2160
2156
|
if (!this.hasDisposer(disposer)) {
|
|
2161
|
-
this._internalEventsRegister("dispose" /*
|
|
2157
|
+
this._internalEventsRegister("dispose" /* Dispose */, disposer, true);
|
|
2162
2158
|
return;
|
|
2163
2159
|
}
|
|
2164
2160
|
throw fail("cannot add a disposer when it is already registered for execution");
|
|
@@ -2169,10 +2165,10 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
2169
2165
|
configurable: true,
|
|
2170
2166
|
writable: true,
|
|
2171
2167
|
value: function (disposer) {
|
|
2172
|
-
if (!this._internalEventsHas("dispose" /*
|
|
2168
|
+
if (!this._internalEventsHas("dispose" /* Dispose */, disposer)) {
|
|
2173
2169
|
throw fail("cannot remove a disposer which was never registered for execution");
|
|
2174
2170
|
}
|
|
2175
|
-
this._internalEventsUnregister("dispose" /*
|
|
2171
|
+
this._internalEventsUnregister("dispose" /* Dispose */, disposer);
|
|
2176
2172
|
}
|
|
2177
2173
|
});
|
|
2178
2174
|
Object.defineProperty(ObjectNode.prototype, "removeMiddleware", {
|
|
@@ -2280,7 +2276,7 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
2280
2276
|
args[_i - 1] = arguments[_i];
|
|
2281
2277
|
}
|
|
2282
2278
|
if (this._internalEvents) {
|
|
2283
|
-
(_a = this._internalEvents).emit.apply(_a,
|
|
2279
|
+
(_a = this._internalEvents).emit.apply(_a, __spread([event], args));
|
|
2284
2280
|
}
|
|
2285
2281
|
}
|
|
2286
2282
|
});
|
|
@@ -2923,11 +2919,11 @@ function serializeArgument(node, actionName, index, arg) {
|
|
|
2923
2919
|
// We should not serialize MST nodes, even if we can, because we don't know if the receiving party can handle a raw snapshot instead of an
|
|
2924
2920
|
// MST type instance. So if one wants to serialize a MST node that was pass in, either explitly pass: 1: an id, 2: a (relative) path, 3: a snapshot
|
|
2925
2921
|
if (isStateTreeNode(arg))
|
|
2926
|
-
return serializeTheUnserializable("[MSTNode: "
|
|
2922
|
+
return serializeTheUnserializable("[MSTNode: " + getType(arg).name + "]");
|
|
2927
2923
|
if (typeof arg === "function")
|
|
2928
2924
|
return serializeTheUnserializable("[function]");
|
|
2929
2925
|
if (typeof arg === "object" && !isPlainObject(arg) && !isArray(arg))
|
|
2930
|
-
return serializeTheUnserializable("[object "
|
|
2926
|
+
return serializeTheUnserializable("[object " + ((arg && arg.constructor && arg.constructor.name) || "Complex Object") + "]");
|
|
2931
2927
|
try {
|
|
2932
2928
|
// Check if serializable, cycle free etc...
|
|
2933
2929
|
// MWE: there must be a better way....
|
|
@@ -2968,7 +2964,7 @@ function applyAction(target, actions) {
|
|
|
2968
2964
|
function baseApplyAction(target, action) {
|
|
2969
2965
|
var resolvedTarget = tryResolve(target, action.path || "");
|
|
2970
2966
|
if (!resolvedTarget)
|
|
2971
|
-
throw fail("Invalid action path: "
|
|
2967
|
+
throw fail("Invalid action path: " + (action.path || ""));
|
|
2972
2968
|
var node = getStateTreeNode(resolvedTarget);
|
|
2973
2969
|
// Reserved functions
|
|
2974
2970
|
if (action.name === "@APPLY_PATCHES") {
|
|
@@ -2978,7 +2974,7 @@ function baseApplyAction(target, action) {
|
|
|
2978
2974
|
return applySnapshot.call(null, resolvedTarget, action.args[0]);
|
|
2979
2975
|
}
|
|
2980
2976
|
if (!(typeof resolvedTarget[action.name] === "function"))
|
|
2981
|
-
throw fail("Action '"
|
|
2977
|
+
throw fail("Action '" + action.name + "' does not exist in '" + node.path + "'");
|
|
2982
2978
|
return resolvedTarget[action.name].apply(resolvedTarget, action.args ? action.args.map(function (v) { return deserializeArgument(node, v); }) : []);
|
|
2983
2979
|
}
|
|
2984
2980
|
/**
|
|
@@ -3183,7 +3179,7 @@ function createActionInvoker(target, name, fn) {
|
|
|
3183
3179
|
tree: getRoot(target),
|
|
3184
3180
|
rootId: parentContext ? parentContext.rootId : id,
|
|
3185
3181
|
parentId: parentContext ? parentContext.id : 0,
|
|
3186
|
-
allParentIds: parentContext ?
|
|
3182
|
+
allParentIds: parentContext ? __spread(parentContext.allParentIds, [parentContext.id]) : [],
|
|
3187
3183
|
parentEvent: parentContext,
|
|
3188
3184
|
parentActionEvent: parentActionContext
|
|
3189
3185
|
}, fn);
|
|
@@ -3339,11 +3335,11 @@ function runMiddleWares(node, baseCall, originalFn) {
|
|
|
3339
3335
|
if (devMode()) {
|
|
3340
3336
|
if (!nextInvoked && !abortInvoked) {
|
|
3341
3337
|
var node2 = getStateTreeNode(call.tree);
|
|
3342
|
-
throw fail("Neither the next() nor the abort() callback within the middleware "
|
|
3338
|
+
throw fail("Neither the next() nor the abort() callback within the middleware " + handler.name + " for the action: \"" + call.name + "\" on the node: " + node2.type.name + " was invoked.");
|
|
3343
3339
|
}
|
|
3344
3340
|
else if (nextInvoked && abortInvoked) {
|
|
3345
3341
|
var node2 = getStateTreeNode(call.tree);
|
|
3346
|
-
throw fail("The next() and abort() callback within the middleware "
|
|
3342
|
+
throw fail("The next() and abort() callback within the middleware " + handler.name + " for the action: \"" + call.name + "\" on the node: " + node2.type.name + " were invoked.");
|
|
3347
3343
|
}
|
|
3348
3344
|
}
|
|
3349
3345
|
return result;
|
|
@@ -3393,7 +3389,7 @@ function safeStringify(value) {
|
|
|
3393
3389
|
}
|
|
3394
3390
|
catch (e) {
|
|
3395
3391
|
// istanbul ignore next
|
|
3396
|
-
return "<Unserializable: "
|
|
3392
|
+
return "<Unserializable: " + e + ">";
|
|
3397
3393
|
}
|
|
3398
3394
|
}
|
|
3399
3395
|
/**
|
|
@@ -3402,15 +3398,15 @@ function safeStringify(value) {
|
|
|
3402
3398
|
*/
|
|
3403
3399
|
function prettyPrintValue(value) {
|
|
3404
3400
|
return typeof value === "function"
|
|
3405
|
-
? "<function"
|
|
3401
|
+
? "<function" + (value.name ? " " + value.name : "") + ">"
|
|
3406
3402
|
: isStateTreeNode(value)
|
|
3407
|
-
? "<"
|
|
3408
|
-
: "`"
|
|
3403
|
+
? "<" + value + ">"
|
|
3404
|
+
: "`" + safeStringify(value) + "`";
|
|
3409
3405
|
}
|
|
3410
3406
|
function shortenPrintValue(valueInString) {
|
|
3411
3407
|
return valueInString.length < 280
|
|
3412
3408
|
? valueInString
|
|
3413
|
-
:
|
|
3409
|
+
: valueInString.substring(0, 272) + "......" + valueInString.substring(valueInString.length - 8);
|
|
3414
3410
|
}
|
|
3415
3411
|
function toErrorString(error) {
|
|
3416
3412
|
var value = error.value;
|
|
@@ -3422,19 +3418,19 @@ function toErrorString(error) {
|
|
|
3422
3418
|
})
|
|
3423
3419
|
.filter(function (path) { return path.length > 0; })
|
|
3424
3420
|
.join("/");
|
|
3425
|
-
var pathPrefix = fullPath.length > 0 ? "at path \"/"
|
|
3421
|
+
var pathPrefix = fullPath.length > 0 ? "at path \"/" + fullPath + "\" " : "";
|
|
3426
3422
|
var currentTypename = isStateTreeNode(value)
|
|
3427
|
-
? "value of type "
|
|
3423
|
+
? "value of type " + getStateTreeNode(value).type.name + ":"
|
|
3428
3424
|
: isPrimitive(value)
|
|
3429
3425
|
? "value"
|
|
3430
3426
|
: "snapshot";
|
|
3431
3427
|
var isSnapshotCompatible = type && isStateTreeNode(value) && type.is(getStateTreeNode(value).snapshot);
|
|
3432
|
-
return (""
|
|
3433
|
-
(error.message ? " ("
|
|
3428
|
+
return ("" + pathPrefix + currentTypename + " " + prettyPrintValue(value) + " is not assignable " + (type ? "to type: `" + type.name + "`" : "") +
|
|
3429
|
+
(error.message ? " (" + error.message + ")" : "") +
|
|
3434
3430
|
(type
|
|
3435
3431
|
? isPrimitiveType(type) || isPrimitive(value)
|
|
3436
3432
|
? "."
|
|
3437
|
-
: ", expected an instance of `"
|
|
3433
|
+
: ", expected an instance of `" + type.name + "` or a snapshot like `" + type.describe() + "` instead." +
|
|
3438
3434
|
(isSnapshotCompatible
|
|
3439
3435
|
? " (Note that a snapshot of the provided value is compatible with the targeted type)"
|
|
3440
3436
|
: "")
|
|
@@ -3497,7 +3493,7 @@ function validationErrorsToString(type, value, errors) {
|
|
|
3497
3493
|
if (errors.length === 0) {
|
|
3498
3494
|
return undefined;
|
|
3499
3495
|
}
|
|
3500
|
-
return ("Error while converting "
|
|
3496
|
+
return ("Error while converting " + shortenPrintValue(prettyPrintValue(value)) + " to `" + type.name + "`:\n\n " + errors.map(toErrorString).join("\n "));
|
|
3501
3497
|
}
|
|
3502
3498
|
|
|
3503
3499
|
var identifierCacheId = 0;
|
|
@@ -3545,7 +3541,7 @@ var IdentifierCache = /** @class */ (function () {
|
|
|
3545
3541
|
writable: true,
|
|
3546
3542
|
value: function (identifier) {
|
|
3547
3543
|
var modificationId = this.lastCacheModificationPerId.get(identifier) || 0;
|
|
3548
|
-
return
|
|
3544
|
+
return this.cacheId + "-" + modificationId;
|
|
3549
3545
|
}
|
|
3550
3546
|
});
|
|
3551
3547
|
Object.defineProperty(IdentifierCache.prototype, "addNodeToCache", {
|
|
@@ -3660,9 +3656,9 @@ var IdentifierCache = /** @class */ (function () {
|
|
|
3660
3656
|
case 1:
|
|
3661
3657
|
return matches[0];
|
|
3662
3658
|
default:
|
|
3663
|
-
throw fail("Cannot resolve a reference to type '"
|
|
3659
|
+
throw fail("Cannot resolve a reference to type '" + type.name + "' with id: '" + identifier + "' unambigously, there are multiple candidates: " + matches
|
|
3664
3660
|
.map(function (n) { return n.path; })
|
|
3665
|
-
.join(", "))
|
|
3661
|
+
.join(", "));
|
|
3666
3662
|
}
|
|
3667
3663
|
}
|
|
3668
3664
|
});
|
|
@@ -3678,7 +3674,7 @@ function createObjectNode(type, parent, subpath, environment, initialValue) {
|
|
|
3678
3674
|
if (existingNode) {
|
|
3679
3675
|
if (existingNode.parent) {
|
|
3680
3676
|
// istanbul ignore next
|
|
3681
|
-
throw fail("Cannot add an object to a state tree if it is already part of the same or another state tree. Tried to assign an object to '"
|
|
3677
|
+
throw fail("Cannot add an object to a state tree if it is already part of the same or another state tree. Tried to assign an object to '" + (parent ? parent.path : "") + "/" + subpath + "', but it lives already at '" + existingNode.path + "'");
|
|
3682
3678
|
}
|
|
3683
3679
|
if (parent) {
|
|
3684
3680
|
existingNode.setParent(parent, subpath);
|
|
@@ -3741,7 +3737,7 @@ function assertIsStateTreeNode(value, argNumber) {
|
|
|
3741
3737
|
function getStateTreeNode(value) {
|
|
3742
3738
|
if (!isStateTreeNode(value)) {
|
|
3743
3739
|
// istanbul ignore next
|
|
3744
|
-
throw fail("Value "
|
|
3740
|
+
throw fail("Value " + value + " is no MST Node");
|
|
3745
3741
|
}
|
|
3746
3742
|
return value.$treenode;
|
|
3747
3743
|
}
|
|
@@ -3767,7 +3763,7 @@ var doubleDot = function (_) { return ".."; };
|
|
|
3767
3763
|
function getRelativePathBetweenNodes(base, target) {
|
|
3768
3764
|
// PRE condition target is (a child of) base!
|
|
3769
3765
|
if (base.root !== target.root) {
|
|
3770
|
-
throw fail("Cannot calculate relative path: objects '"
|
|
3766
|
+
throw fail("Cannot calculate relative path: objects '" + base + "' and '" + target + "' are not part of the same object tree");
|
|
3771
3767
|
}
|
|
3772
3768
|
var baseParts = splitJsonPath(base.path);
|
|
3773
3769
|
var targetParts = splitJsonPath(target.path);
|
|
@@ -3824,7 +3820,7 @@ function resolveNodeByPathParts(base, pathParts, failIfResolveFails) {
|
|
|
3824
3820
|
}
|
|
3825
3821
|
}
|
|
3826
3822
|
}
|
|
3827
|
-
throw fail("Could not resolve '"
|
|
3823
|
+
throw fail("Could not resolve '" + part + "' in path '" + (joinJsonPath(pathParts.slice(0, i)) || "/") + "' while resolving '" + joinJsonPath(pathParts) + "'");
|
|
3828
3824
|
}
|
|
3829
3825
|
}
|
|
3830
3826
|
catch (e) {
|
|
@@ -4144,7 +4140,7 @@ var EventHandler = /** @class */ (function () {
|
|
|
4144
4140
|
}
|
|
4145
4141
|
// make a copy just in case it changes
|
|
4146
4142
|
var handlers = this.handlers.slice();
|
|
4147
|
-
handlers.forEach(function (f) { return f.apply(void 0,
|
|
4143
|
+
handlers.forEach(function (f) { return f.apply(void 0, __spread(args)); });
|
|
4148
4144
|
}
|
|
4149
4145
|
});
|
|
4150
4146
|
return EventHandler;
|
|
@@ -4237,7 +4233,7 @@ var EventHandlers = /** @class */ (function () {
|
|
|
4237
4233
|
}
|
|
4238
4234
|
var handler = this.eventHandlers && this.eventHandlers[event];
|
|
4239
4235
|
if (handler) {
|
|
4240
|
-
(_a = handler).emit.apply(_a,
|
|
4236
|
+
(_a = handler).emit.apply(_a, __spread(args));
|
|
4241
4237
|
}
|
|
4242
4238
|
}
|
|
4243
4239
|
});
|
|
@@ -4282,7 +4278,7 @@ deprecated.ids = {};
|
|
|
4282
4278
|
* @hidden
|
|
4283
4279
|
*/
|
|
4284
4280
|
function warnError(msg) {
|
|
4285
|
-
console.warn(new Error("[mobx-state-tree] "
|
|
4281
|
+
console.warn(new Error("[mobx-state-tree] " + msg));
|
|
4286
4282
|
}
|
|
4287
4283
|
/**
|
|
4288
4284
|
* @internal
|
|
@@ -4307,7 +4303,7 @@ function assertArg(value, fn, typeName, argNumber) {
|
|
|
4307
4303
|
if (devMode()) {
|
|
4308
4304
|
if (!fn(value)) {
|
|
4309
4305
|
// istanbul ignore next
|
|
4310
|
-
throw fail("expected "
|
|
4306
|
+
throw fail("expected " + typeName + " as argument " + asArray(argNumber).join(" or ") + ", got " + value + " instead");
|
|
4311
4307
|
}
|
|
4312
4308
|
}
|
|
4313
4309
|
}
|
|
@@ -4325,10 +4321,10 @@ function assertIsFunction(value, argNumber) {
|
|
|
4325
4321
|
function assertIsNumber(value, argNumber, min, max) {
|
|
4326
4322
|
assertArg(value, function (n) { return typeof n === "number"; }, "number", argNumber);
|
|
4327
4323
|
if (min !== undefined) {
|
|
4328
|
-
assertArg(value, function (n) { return n >= min; }, "number greater than "
|
|
4324
|
+
assertArg(value, function (n) { return n >= min; }, "number greater than " + min, argNumber);
|
|
4329
4325
|
}
|
|
4330
4326
|
if (max !== undefined) {
|
|
4331
|
-
assertArg(value, function (n) { return n <= max; }, "number lesser than "
|
|
4327
|
+
assertArg(value, function (n) { return n <= max; }, "number lesser than " + max, argNumber);
|
|
4332
4328
|
}
|
|
4333
4329
|
}
|
|
4334
4330
|
/**
|
|
@@ -4407,7 +4403,7 @@ function toGeneratorFunction(p) {
|
|
|
4407
4403
|
}
|
|
4408
4404
|
return __generator(this, function (_a) {
|
|
4409
4405
|
switch (_a.label) {
|
|
4410
|
-
case 0: return [4 /*yield*/, p.apply(void 0,
|
|
4406
|
+
case 0: return [4 /*yield*/, p.apply(void 0, __spread(args))];
|
|
4411
4407
|
case 1: return [2 /*return*/, (_a.sent())];
|
|
4412
4408
|
}
|
|
4413
4409
|
});
|
|
@@ -4464,7 +4460,7 @@ function createFlowSpawner(name, generator) {
|
|
|
4464
4460
|
tree: parentContext.tree,
|
|
4465
4461
|
context: parentContext.context,
|
|
4466
4462
|
parentId: parentContext.id,
|
|
4467
|
-
allParentIds:
|
|
4463
|
+
allParentIds: __spread(parentContext.allParentIds, [parentContext.id]),
|
|
4468
4464
|
rootId: parentContext.rootId,
|
|
4469
4465
|
parentEvent: parentContext,
|
|
4470
4466
|
parentActionEvent: parentActionContext
|
|
@@ -4644,7 +4640,7 @@ function splitJsonPath(path) {
|
|
|
4644
4640
|
stringStartsWith(path, "./") ||
|
|
4645
4641
|
stringStartsWith(path, "../");
|
|
4646
4642
|
if (!valid) {
|
|
4647
|
-
throw fail("a json path must be either rooted, empty or relative, but got '"
|
|
4643
|
+
throw fail("a json path must be either rooted, empty or relative, but got '" + path + "'");
|
|
4648
4644
|
}
|
|
4649
4645
|
// '/a/b/c' -> ["a", "b", "c"]
|
|
4650
4646
|
// '../../b/c' -> ["..", "..", "b", "c"]
|
|
@@ -4690,7 +4686,7 @@ var SnapshotProcessor = /** @class */ (function (_super) {
|
|
|
4690
4686
|
configurable: true,
|
|
4691
4687
|
writable: true,
|
|
4692
4688
|
value: function () {
|
|
4693
|
-
return "snapshotProcessor("
|
|
4689
|
+
return "snapshotProcessor(" + this._subtype.describe() + ")";
|
|
4694
4690
|
}
|
|
4695
4691
|
});
|
|
4696
4692
|
Object.defineProperty(SnapshotProcessor.prototype, "preProcessSnapshot", {
|
|
@@ -5106,7 +5102,7 @@ var MapType = /** @class */ (function (_super) {
|
|
|
5106
5102
|
if (!type.identifierAttribute)
|
|
5107
5103
|
return current;
|
|
5108
5104
|
if (current && current !== type.identifierAttribute) {
|
|
5109
|
-
throw fail("The objects in a map should all have the same identifier attribute, expected '"
|
|
5105
|
+
throw fail("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");
|
|
5110
5106
|
}
|
|
5111
5107
|
return type.identifierAttribute;
|
|
5112
5108
|
}, undefined);
|
|
@@ -5230,7 +5226,7 @@ var MapType = /** @class */ (function (_super) {
|
|
|
5230
5226
|
if (this.identifierMode === MapIdentifierMode.YES && node instanceof ObjectNode) {
|
|
5231
5227
|
var identifier = node.identifier;
|
|
5232
5228
|
if (identifier !== expected)
|
|
5233
|
-
throw fail("A map of objects containing an identifier should always store the object under their own identifier. Trying to store key '"
|
|
5229
|
+
throw fail("A map of objects containing an identifier should always store the object under their own identifier. Trying to store key '" + identifier + "', but expected: '" + expected + "'");
|
|
5234
5230
|
}
|
|
5235
5231
|
}
|
|
5236
5232
|
});
|
|
@@ -5402,7 +5398,7 @@ MapType.prototype.applySnapshot = mobx.action(MapType.prototype.applySnapshot);
|
|
|
5402
5398
|
* @returns
|
|
5403
5399
|
*/
|
|
5404
5400
|
function map(subtype) {
|
|
5405
|
-
return new MapType("Map<string, "
|
|
5401
|
+
return new MapType("Map<string, " + subtype.name + ">", subtype);
|
|
5406
5402
|
}
|
|
5407
5403
|
/**
|
|
5408
5404
|
* Returns if a given value represents a map type.
|
|
@@ -5719,7 +5715,7 @@ ArrayType.prototype.applySnapshot = mobx.action(ArrayType.prototype.applySnapsho
|
|
|
5719
5715
|
*/
|
|
5720
5716
|
function array(subtype) {
|
|
5721
5717
|
assertIsType(subtype, 1);
|
|
5722
|
-
return new ArrayType(
|
|
5718
|
+
return new ArrayType(subtype.name + "[]", subtype);
|
|
5723
5719
|
}
|
|
5724
5720
|
function reconcileArrayChildren(parent, childType, oldNodes, newValues, newPaths) {
|
|
5725
5721
|
var nothingChanged = true;
|
|
@@ -5753,7 +5749,7 @@ function reconcileArrayChildren(parent, childType, oldNodes, newValues, newPaths
|
|
|
5753
5749
|
// check if already belongs to the same parent. if so, avoid pushing item in. only swapping can occur.
|
|
5754
5750
|
if (isStateTreeNode(newValue) && getStateTreeNode(newValue).parent === parent) {
|
|
5755
5751
|
// this node is owned by this parent, but not in the reconcilable set, so it must be double
|
|
5756
|
-
throw fail("Cannot add an object to a state tree if it is already part of the same or another state tree. Tried to assign an object to '"
|
|
5752
|
+
throw fail("Cannot add an object to a state tree if it is already part of the same or another state tree. Tried to assign an object to '" + parent.path + "/" + newPath + "', but it lives already at '" + getStateTreeNode(newValue).path + "'");
|
|
5757
5753
|
}
|
|
5758
5754
|
nothingChanged = false;
|
|
5759
5755
|
var newNode = valueAsNode(childType, parent, newPath, newValue);
|
|
@@ -5869,7 +5865,7 @@ function toPropertiesObject(declaredProps) {
|
|
|
5869
5865
|
var alreadySeenKeys = new Set();
|
|
5870
5866
|
keysList.forEach(function (key) {
|
|
5871
5867
|
if (alreadySeenKeys.has(key)) {
|
|
5872
|
-
throw fail(
|
|
5868
|
+
throw fail(key + " is declared twice in the model. Model should not contain the same keys");
|
|
5873
5869
|
}
|
|
5874
5870
|
alreadySeenKeys.add(key);
|
|
5875
5871
|
});
|
|
@@ -5877,7 +5873,7 @@ function toPropertiesObject(declaredProps) {
|
|
|
5877
5873
|
return keysList.reduce(function (props, key) {
|
|
5878
5874
|
// warn if user intended a HOOK
|
|
5879
5875
|
if (key in Hook) {
|
|
5880
|
-
throw fail("Hook '"
|
|
5876
|
+
throw fail("Hook '" + key + "' was defined as property. Hooks should be defined as part of the actions");
|
|
5881
5877
|
}
|
|
5882
5878
|
// the user intended to use a view
|
|
5883
5879
|
var descriptor = Object.getOwnPropertyDescriptor(declaredProps, key);
|
|
@@ -5904,17 +5900,17 @@ function toPropertiesObject(declaredProps) {
|
|
|
5904
5900
|
else if (isType(value)) ;
|
|
5905
5901
|
// its a function, maybe the user wanted a view?
|
|
5906
5902
|
else if (devMode() && typeof value === "function") {
|
|
5907
|
-
throw fail("Invalid type definition for property '"
|
|
5903
|
+
throw fail("Invalid type definition for property '" + key + "', it looks like you passed a function. Did you forget to invoke it, or did you intend to declare a view / action?");
|
|
5908
5904
|
}
|
|
5909
5905
|
// no other complex values
|
|
5910
5906
|
else if (devMode() && typeof value === "object") {
|
|
5911
|
-
throw fail("Invalid type definition for property '"
|
|
5907
|
+
throw fail("Invalid type definition for property '" + key + "', it looks like you passed an object. Try passing another model type or a types.frozen.");
|
|
5912
5908
|
}
|
|
5913
5909
|
else {
|
|
5914
|
-
throw fail("Invalid type definition for property '"
|
|
5910
|
+
throw fail("Invalid type definition for property '" + key + "', cannot infer a type from a value like '" + value + "' (" + typeof value + ")");
|
|
5915
5911
|
}
|
|
5916
5912
|
return props;
|
|
5917
|
-
}, declaredProps);
|
|
5913
|
+
}, __assign({}, declaredProps));
|
|
5918
5914
|
}
|
|
5919
5915
|
/**
|
|
5920
5916
|
* @internal
|
|
@@ -6024,7 +6020,7 @@ var ModelType = /** @class */ (function (_super) {
|
|
|
6024
6020
|
this.forAllProps(function (propName, propType) {
|
|
6025
6021
|
if (propType.flags & TypeFlags.Identifier) {
|
|
6026
6022
|
if (identifierAttribute)
|
|
6027
|
-
throw fail("Cannot define property '"
|
|
6023
|
+
throw fail("Cannot define property '" + propName + "' as object identifier, property '" + identifierAttribute + "' is already defined as identifier property");
|
|
6028
6024
|
identifierAttribute = propName;
|
|
6029
6025
|
}
|
|
6030
6026
|
});
|
|
@@ -6070,10 +6066,10 @@ var ModelType = /** @class */ (function (_super) {
|
|
|
6070
6066
|
Object.keys(actions).forEach(function (name) {
|
|
6071
6067
|
// warn if preprocessor was given
|
|
6072
6068
|
if (name === PRE_PROCESS_SNAPSHOT)
|
|
6073
|
-
throw fail("Cannot define action '"
|
|
6069
|
+
throw fail("Cannot define action '" + PRE_PROCESS_SNAPSHOT + "', it should be defined using 'type.preProcessSnapshot(fn)' instead");
|
|
6074
6070
|
// warn if postprocessor was given
|
|
6075
6071
|
if (name === POST_PROCESS_SNAPSHOT)
|
|
6076
|
-
throw fail("Cannot define action '"
|
|
6072
|
+
throw fail("Cannot define action '" + POST_PROCESS_SNAPSHOT + "', it should be defined using 'type.postProcessSnapshot(fn)' instead");
|
|
6077
6073
|
var action2 = actions[name];
|
|
6078
6074
|
// apply hook composition
|
|
6079
6075
|
var baseAction = self[name];
|
|
@@ -6103,7 +6099,7 @@ var ModelType = /** @class */ (function (_super) {
|
|
|
6103
6099
|
value: function (fn) {
|
|
6104
6100
|
var _this = this;
|
|
6105
6101
|
if (typeof fn !== "function") {
|
|
6106
|
-
throw fail("You passed an "
|
|
6102
|
+
throw fail("You passed an " + typeof fn + " to volatile state as an argument, when function is expected");
|
|
6107
6103
|
}
|
|
6108
6104
|
var stateInitializer = function (self) {
|
|
6109
6105
|
_this.instantiateVolatileState(self, fn(self));
|
|
@@ -6132,7 +6128,7 @@ var ModelType = /** @class */ (function (_super) {
|
|
|
6132
6128
|
var initializer = function (self) {
|
|
6133
6129
|
var _a = fn(self), actions = _a.actions, views = _a.views, state = _a.state, rest = __rest(_a, ["actions", "views", "state"]);
|
|
6134
6130
|
for (var key in rest)
|
|
6135
|
-
throw fail("The `extend` function should return an object with a subset of the fields 'actions', 'views' and 'state'. Found invalid key '"
|
|
6131
|
+
throw fail("The `extend` function should return an object with a subset of the fields 'actions', 'views' and 'state'. Found invalid key '" + key + "'");
|
|
6136
6132
|
if (state)
|
|
6137
6133
|
_this.instantiateVolatileState(self, state);
|
|
6138
6134
|
if (views)
|
|
@@ -6316,7 +6312,7 @@ var ModelType = /** @class */ (function (_super) {
|
|
|
6316
6312
|
atom.reportObserved();
|
|
6317
6313
|
}
|
|
6318
6314
|
catch (e) {
|
|
6319
|
-
throw fail(
|
|
6315
|
+
throw fail(name + " property is declared twice");
|
|
6320
6316
|
}
|
|
6321
6317
|
res[name] = _this.getChildNode(node, name).snapshot;
|
|
6322
6318
|
});
|
|
@@ -6344,7 +6340,7 @@ var ModelType = /** @class */ (function (_super) {
|
|
|
6344
6340
|
writable: true,
|
|
6345
6341
|
value: function (node, subpath, patch) {
|
|
6346
6342
|
if (!(patch.op === "replace" || patch.op === "add")) {
|
|
6347
|
-
throw fail("object does not support operation "
|
|
6343
|
+
throw fail("object does not support operation " + patch.op);
|
|
6348
6344
|
}
|
|
6349
6345
|
node.storedValue[subpath] = patch.value;
|
|
6350
6346
|
}
|
|
@@ -6576,7 +6572,7 @@ var CoreType = /** @class */ (function (_super) {
|
|
|
6576
6572
|
return typeCheckSuccess();
|
|
6577
6573
|
}
|
|
6578
6574
|
var typeName = this.name === "Date" ? "Date or a unix milliseconds timestamp" : this.name;
|
|
6579
|
-
return typeCheckFailure(context, value, "Value is not a "
|
|
6575
|
+
return typeCheckFailure(context, value, "Value is not a " + typeName);
|
|
6580
6576
|
}
|
|
6581
6577
|
});
|
|
6582
6578
|
return CoreType;
|
|
@@ -6769,7 +6765,7 @@ var Literal = /** @class */ (function (_super) {
|
|
|
6769
6765
|
if (isPrimitive(value) && value === this.value) {
|
|
6770
6766
|
return typeCheckSuccess();
|
|
6771
6767
|
}
|
|
6772
|
-
return typeCheckFailure(context, value, "Value is not a literal "
|
|
6768
|
+
return typeCheckFailure(context, value, "Value is not a literal " + JSON.stringify(this.value));
|
|
6773
6769
|
}
|
|
6774
6770
|
});
|
|
6775
6771
|
return Literal;
|
|
@@ -6951,7 +6947,7 @@ function enumeration(name, options) {
|
|
|
6951
6947
|
assertIsString(option, i + 1);
|
|
6952
6948
|
});
|
|
6953
6949
|
}
|
|
6954
|
-
var type = union.apply(void 0,
|
|
6950
|
+
var type = union.apply(void 0, __spread(realOptions.map(function (option) { return literal("" + option); })));
|
|
6955
6951
|
if (typeof name === "string")
|
|
6956
6952
|
type.name = name;
|
|
6957
6953
|
return type;
|
|
@@ -7047,7 +7043,7 @@ var Union = /** @class */ (function (_super) {
|
|
|
7047
7043
|
if (this._dispatcher) {
|
|
7048
7044
|
return this._dispatcher(value);
|
|
7049
7045
|
}
|
|
7050
|
-
// find the most
|
|
7046
|
+
// find the most accomodating type
|
|
7051
7047
|
// if we are using reconciliation try the current node type first (fix for #1045)
|
|
7052
7048
|
if (reconcileCurrentType) {
|
|
7053
7049
|
if (reconcileCurrentType.is(value)) {
|
|
@@ -7111,7 +7107,7 @@ function union(optionsOrType) {
|
|
|
7111
7107
|
otherTypes[_i - 1] = arguments[_i];
|
|
7112
7108
|
}
|
|
7113
7109
|
var options = isType(optionsOrType) ? undefined : optionsOrType;
|
|
7114
|
-
var types = isType(optionsOrType) ?
|
|
7110
|
+
var types = isType(optionsOrType) ? __spread([optionsOrType], otherTypes) : otherTypes;
|
|
7115
7111
|
var name = "(" + types.map(function (type) { return type.name; }).join(" | ") + ")";
|
|
7116
7112
|
// check all options
|
|
7117
7113
|
if (devMode()) {
|
|
@@ -7473,7 +7469,7 @@ var Late = /** @class */ (function (_super) {
|
|
|
7473
7469
|
* @returns
|
|
7474
7470
|
*/
|
|
7475
7471
|
function late(nameOrType, maybeType) {
|
|
7476
|
-
var name = typeof nameOrType === "string" ? nameOrType : "late("
|
|
7472
|
+
var name = typeof nameOrType === "string" ? nameOrType : "late(" + nameOrType.toString() + ")";
|
|
7477
7473
|
var type = typeof nameOrType === "string" ? maybeType : nameOrType;
|
|
7478
7474
|
// checks that the type is actually a late type
|
|
7479
7475
|
if (devMode()) {
|
|
@@ -7545,7 +7541,7 @@ var Lazy = /** @class */ (function (_super) {
|
|
|
7545
7541
|
node.parent.applyPatches([
|
|
7546
7542
|
{
|
|
7547
7543
|
op: "replace",
|
|
7548
|
-
path: "/"
|
|
7544
|
+
path: "/" + node.subpath,
|
|
7549
7545
|
value: node.snapshot
|
|
7550
7546
|
}
|
|
7551
7547
|
]);
|
|
@@ -7559,7 +7555,7 @@ var Lazy = /** @class */ (function (_super) {
|
|
|
7559
7555
|
configurable: true,
|
|
7560
7556
|
writable: true,
|
|
7561
7557
|
value: function () {
|
|
7562
|
-
return "<lazy "
|
|
7558
|
+
return "<lazy " + this.name + ">";
|
|
7563
7559
|
}
|
|
7564
7560
|
});
|
|
7565
7561
|
Object.defineProperty(Lazy.prototype, "instantiate", {
|
|
@@ -7613,7 +7609,7 @@ var Lazy = /** @class */ (function (_super) {
|
|
|
7613
7609
|
var Frozen = /** @class */ (function (_super) {
|
|
7614
7610
|
__extends(Frozen, _super);
|
|
7615
7611
|
function Frozen(subType) {
|
|
7616
|
-
var _this = _super.call(this, subType ? "frozen("
|
|
7612
|
+
var _this = _super.call(this, subType ? "frozen(" + subType.name + ")" : "frozen") || this;
|
|
7617
7613
|
Object.defineProperty(_this, "subType", {
|
|
7618
7614
|
enumerable: true,
|
|
7619
7615
|
configurable: true,
|
|
@@ -7769,7 +7765,7 @@ var StoredReference = /** @class */ (function () {
|
|
|
7769
7765
|
this.identifier = id;
|
|
7770
7766
|
}
|
|
7771
7767
|
else {
|
|
7772
|
-
throw fail("Can only store references to tree nodes or identifiers, got: '"
|
|
7768
|
+
throw fail("Can only store references to tree nodes or identifiers, got: '" + value + "'");
|
|
7773
7769
|
}
|
|
7774
7770
|
}
|
|
7775
7771
|
Object.defineProperty(StoredReference.prototype, "updateResolvedReference", {
|
|
@@ -7786,7 +7782,7 @@ var StoredReference = /** @class */ (function () {
|
|
|
7786
7782
|
// reference was initialized with the identifier of the target
|
|
7787
7783
|
var target = root.identifierCache.resolve(targetType, normalizedId);
|
|
7788
7784
|
if (!target) {
|
|
7789
|
-
throw new InvalidReferenceError("[mobx-state-tree] Failed to resolve reference '"
|
|
7785
|
+
throw new InvalidReferenceError("[mobx-state-tree] Failed to resolve reference '" + this.identifier + "' to type '" + this.targetType.name + "' (from node: " + node.path + ")");
|
|
7790
7786
|
}
|
|
7791
7787
|
this.resolvedReference = {
|
|
7792
7788
|
node: target,
|
|
@@ -7825,7 +7821,7 @@ var InvalidReferenceError = /** @class */ (function (_super) {
|
|
|
7825
7821
|
var BaseReferenceType = /** @class */ (function (_super) {
|
|
7826
7822
|
__extends(BaseReferenceType, _super);
|
|
7827
7823
|
function BaseReferenceType(targetType, onInvalidated) {
|
|
7828
|
-
var _this = _super.call(this, "reference("
|
|
7824
|
+
var _this = _super.call(this, "reference(" + targetType.name + ")") || this;
|
|
7829
7825
|
Object.defineProperty(_this, "targetType", {
|
|
7830
7826
|
enumerable: true,
|
|
7831
7827
|
configurable: true,
|
|
@@ -8250,7 +8246,7 @@ var BaseIdentifierType = /** @class */ (function (_super) {
|
|
|
8250
8246
|
value: function (current, newValue, parent, subpath) {
|
|
8251
8247
|
// we don't consider detaching here since identifier are scalar nodes, and scalar nodes cannot be detached
|
|
8252
8248
|
if (current.storedValue !== newValue)
|
|
8253
|
-
throw fail("Tried to change identifier from '"
|
|
8249
|
+
throw fail("Tried to change identifier from '" + current.storedValue + "' to '" + newValue + "'. Changing identifiers is not allowed.");
|
|
8254
8250
|
current.setParent(parent, subpath);
|
|
8255
8251
|
return current;
|
|
8256
8252
|
}
|
|
@@ -8261,7 +8257,7 @@ var BaseIdentifierType = /** @class */ (function (_super) {
|
|
|
8261
8257
|
writable: true,
|
|
8262
8258
|
value: function (value, context) {
|
|
8263
8259
|
if (typeof value !== this.validType) {
|
|
8264
|
-
return typeCheckFailure(context, value, "Value is not a valid "
|
|
8260
|
+
return typeCheckFailure(context, value, "Value is not a valid " + this.describe() + ", expected a " + this.validType);
|
|
8265
8261
|
}
|
|
8266
8262
|
return typeCheckSuccess();
|
|
8267
8263
|
}
|
|
@@ -8472,7 +8468,7 @@ var CustomType = /** @class */ (function (_super) {
|
|
|
8472
8468
|
return typeCheckSuccess();
|
|
8473
8469
|
var typeError = this.options.getValidationMessage(value);
|
|
8474
8470
|
if (typeError) {
|
|
8475
|
-
return typeCheckFailure(context, value, "Invalid value for type '"
|
|
8471
|
+
return typeCheckFailure(context, value, "Invalid value for type '" + this.name + "': " + typeError);
|
|
8476
8472
|
}
|
|
8477
8473
|
return typeCheckSuccess();
|
|
8478
8474
|
}
|