mobx-state-tree 5.4.1 → 5.4.2-pre.1
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 +116 -108
- package/dist/mobx-state-tree.min.js +1 -16
- package/dist/mobx-state-tree.module.js +116 -108
- package/dist/mobx-state-tree.umd.js +118 -110
- package/dist/mobx-state-tree.umd.min.js +1 -16
- package/dist/types/complex-types/model.d.ts +20 -25
- 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 +7 -37
- 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, SuppressedError, Symbol */
|
|
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 (_) try {
|
|
112
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) 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,12 +160,20 @@ function __read(o, n) {
|
|
|
160
160
|
return ar;
|
|
161
161
|
}
|
|
162
162
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
}
|
|
163
|
+
function __spreadArray(to, from, pack) {
|
|
164
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
165
|
+
if (ar || !(i in from)) {
|
|
166
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
167
|
+
ar[i] = from[i];
|
|
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
|
+
};
|
|
169
177
|
|
|
170
178
|
/**
|
|
171
179
|
* Returns the _actual_ type of the given tree node. (Or throws)
|
|
@@ -463,7 +471,7 @@ function getParent(target, depth) {
|
|
|
463
471
|
return parent.storedValue;
|
|
464
472
|
parent = parent.parent;
|
|
465
473
|
}
|
|
466
|
-
throw fail("Failed to find the parent of "
|
|
474
|
+
throw fail("Failed to find the parent of ".concat(getStateTreeNode(target), " at depth ").concat(depth));
|
|
467
475
|
}
|
|
468
476
|
/**
|
|
469
477
|
* 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
|
|
@@ -501,7 +509,7 @@ function getParentOfType(target, type) {
|
|
|
501
509
|
return parent.storedValue;
|
|
502
510
|
parent = parent.parent;
|
|
503
511
|
}
|
|
504
|
-
throw fail("Failed to find the parent of "
|
|
512
|
+
throw fail("Failed to find the parent of ".concat(getStateTreeNode(target), " of a given type"));
|
|
505
513
|
}
|
|
506
514
|
/**
|
|
507
515
|
* Given an object in a model tree, returns the root object of that tree.
|
|
@@ -1356,7 +1364,7 @@ var ScalarNode = /** @class */ (function (_super) {
|
|
|
1356
1364
|
writable: true,
|
|
1357
1365
|
value: function () {
|
|
1358
1366
|
var path = (this.isAlive ? this.path : this.pathUponDeath) || "<root>";
|
|
1359
|
-
return this.type.name
|
|
1367
|
+
return "".concat(this.type.name, "@").concat(path).concat(this.isAlive ? "" : " [dead]");
|
|
1360
1368
|
}
|
|
1361
1369
|
});
|
|
1362
1370
|
Object.defineProperty(ScalarNode.prototype, "die", {
|
|
@@ -1502,7 +1510,7 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
1502
1510
|
enumerable: true,
|
|
1503
1511
|
configurable: true,
|
|
1504
1512
|
writable: true,
|
|
1505
|
-
value: 0 /* UNINITIALIZED */
|
|
1513
|
+
value: 0 /* ObservableInstanceLifecycle.UNINITIALIZED */
|
|
1506
1514
|
});
|
|
1507
1515
|
Object.defineProperty(_this, "_childNodes", {
|
|
1508
1516
|
enumerable: true,
|
|
@@ -1569,7 +1577,7 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
1569
1577
|
}
|
|
1570
1578
|
}
|
|
1571
1579
|
if (typeof id !== "string" && typeof id !== "number") {
|
|
1572
|
-
throw fail("Instance identifier '"
|
|
1580
|
+
throw fail("Instance identifier '".concat(_this.identifierAttribute, "' for type '").concat(_this.type.name, "' must be a string or a number"));
|
|
1573
1581
|
}
|
|
1574
1582
|
// normalize internal identifier to string
|
|
1575
1583
|
_this.identifier = normalizeIdentifier(id);
|
|
@@ -1607,7 +1615,7 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
1607
1615
|
writable: true,
|
|
1608
1616
|
value: function (fireHooks) {
|
|
1609
1617
|
if (fireHooks === void 0) { fireHooks = true; }
|
|
1610
|
-
if (this._observableInstanceState === 0 /* UNINITIALIZED */) {
|
|
1618
|
+
if (this._observableInstanceState === 0 /* ObservableInstanceLifecycle.UNINITIALIZED */) {
|
|
1611
1619
|
this.createObservableInstance(fireHooks);
|
|
1612
1620
|
}
|
|
1613
1621
|
}
|
|
@@ -1625,7 +1633,7 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
1625
1633
|
throw fail("assertion failed: the creation of the observable instance must be done on the initializing phase");
|
|
1626
1634
|
}
|
|
1627
1635
|
}
|
|
1628
|
-
this._observableInstanceState = 1 /* CREATING */;
|
|
1636
|
+
this._observableInstanceState = 1 /* ObservableInstanceLifecycle.CREATING */;
|
|
1629
1637
|
// make sure the parent chain is created as well
|
|
1630
1638
|
// array with parent chain from parent to child
|
|
1631
1639
|
var parentChain = [];
|
|
@@ -1635,7 +1643,7 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
1635
1643
|
// this is done to avoid traversing the whole tree to the root when using
|
|
1636
1644
|
// the same reference again
|
|
1637
1645
|
while (parent &&
|
|
1638
|
-
parent._observableInstanceState === 0 /* UNINITIALIZED */) {
|
|
1646
|
+
parent._observableInstanceState === 0 /* ObservableInstanceLifecycle.UNINITIALIZED */) {
|
|
1639
1647
|
parentChain.unshift(parent);
|
|
1640
1648
|
parent = parent.parent;
|
|
1641
1649
|
}
|
|
@@ -1669,7 +1677,7 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
1669
1677
|
finally {
|
|
1670
1678
|
this._isRunningAction = false;
|
|
1671
1679
|
}
|
|
1672
|
-
this._observableInstanceState = 2 /* CREATED */;
|
|
1680
|
+
this._observableInstanceState = 2 /* ObservableInstanceLifecycle.CREATED */;
|
|
1673
1681
|
this._snapshotComputed.trackAndCompute();
|
|
1674
1682
|
if (this.isRoot)
|
|
1675
1683
|
this._addSnapshotReaction();
|
|
@@ -1752,10 +1760,10 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
1752
1760
|
throw fail("assertion failed: new parent expected");
|
|
1753
1761
|
}
|
|
1754
1762
|
if (this.parent && parentChanged) {
|
|
1755
|
-
throw fail("A node cannot exists twice in the state tree. Failed to add "
|
|
1763
|
+
throw fail("A node cannot exists twice in the state tree. Failed to add ".concat(this, " to path '").concat(newParent.path, "/").concat(subpath, "'."));
|
|
1756
1764
|
}
|
|
1757
1765
|
if (!this.parent && newParent.root === this) {
|
|
1758
|
-
throw fail("A state tree is not allowed to contain itself. Cannot assign "
|
|
1766
|
+
throw fail("A state tree is not allowed to contain itself. Cannot assign ".concat(this, " to path '").concat(newParent.path, "/").concat(subpath, "'"));
|
|
1759
1767
|
}
|
|
1760
1768
|
if (!this.parent && !!this.environment && this.environment !== newParent.root.environment) {
|
|
1761
1769
|
throw fail("A state tree cannot be made part of another state tree as long as their environments are different.");
|
|
@@ -1814,7 +1822,7 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
1814
1822
|
value: function () {
|
|
1815
1823
|
if (!this.isAlive)
|
|
1816
1824
|
return this._snapshotUponDeath;
|
|
1817
|
-
return this._observableInstanceState === 2 /* CREATED */
|
|
1825
|
+
return this._observableInstanceState === 2 /* ObservableInstanceLifecycle.CREATED */
|
|
1818
1826
|
? this._getActualSnapshot()
|
|
1819
1827
|
: this._getCachedInitialSnapshot();
|
|
1820
1828
|
}
|
|
@@ -1887,9 +1895,9 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
1887
1895
|
if (actionContext && actionContext.name != null) {
|
|
1888
1896
|
// try to use the context, and if it not available use the node one
|
|
1889
1897
|
var actionPath = (actionContext && actionContext.context && getPath(actionContext.context)) || escapedPath;
|
|
1890
|
-
actionFullPath = actionPath
|
|
1898
|
+
actionFullPath = "".concat(actionPath, ".").concat(actionContext.name, "()");
|
|
1891
1899
|
}
|
|
1892
|
-
return "You are trying to read or write to an object that is no longer part of a state tree. (Object type: '"
|
|
1900
|
+
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.");
|
|
1893
1901
|
}
|
|
1894
1902
|
});
|
|
1895
1903
|
Object.defineProperty(ObjectNode.prototype, "getChildNode", {
|
|
@@ -1902,7 +1910,7 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
1902
1910
|
});
|
|
1903
1911
|
this._autoUnbox = false;
|
|
1904
1912
|
try {
|
|
1905
|
-
return this._observableInstanceState === 2 /* CREATED */
|
|
1913
|
+
return this._observableInstanceState === 2 /* ObservableInstanceLifecycle.CREATED */
|
|
1906
1914
|
? this.type.getChildNode(this, subpath)
|
|
1907
1915
|
: this._childNodes[subpath];
|
|
1908
1916
|
}
|
|
@@ -1919,7 +1927,7 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
1919
1927
|
this.assertAlive(EMPTY_OBJECT);
|
|
1920
1928
|
this._autoUnbox = false;
|
|
1921
1929
|
try {
|
|
1922
|
-
return this._observableInstanceState === 2 /* CREATED */
|
|
1930
|
+
return this._observableInstanceState === 2 /* ObservableInstanceLifecycle.CREATED */
|
|
1923
1931
|
? this.type.getChildren(this)
|
|
1924
1932
|
: convertChildNodesToArray(this._childNodes);
|
|
1925
1933
|
}
|
|
@@ -1950,7 +1958,7 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
1950
1958
|
value: function (context) {
|
|
1951
1959
|
this.assertAlive(context);
|
|
1952
1960
|
if (!this.isRunningAction() && this.isProtected) {
|
|
1953
|
-
throw fail("Cannot modify '"
|
|
1961
|
+
throw fail("Cannot modify '".concat(this, "', the object is protected and can only be modified by using an action."));
|
|
1954
1962
|
}
|
|
1955
1963
|
}
|
|
1956
1964
|
});
|
|
@@ -1982,8 +1990,8 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
1982
1990
|
writable: true,
|
|
1983
1991
|
value: function () {
|
|
1984
1992
|
var path = (this.isAlive ? this.path : this.pathUponDeath) || "<root>";
|
|
1985
|
-
var identifier = this.identifier ? "(id: "
|
|
1986
|
-
return this.type.name
|
|
1993
|
+
var identifier = this.identifier ? "(id: ".concat(this.identifier, ")") : "";
|
|
1994
|
+
return "".concat(this.type.name, "@").concat(path).concat(identifier).concat(this.isAlive ? "" : " [dead]");
|
|
1987
1995
|
}
|
|
1988
1996
|
});
|
|
1989
1997
|
Object.defineProperty(ObjectNode.prototype, "finalizeCreation", {
|
|
@@ -2065,7 +2073,7 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
2065
2073
|
configurable: true,
|
|
2066
2074
|
writable: true,
|
|
2067
2075
|
value: function () {
|
|
2068
|
-
if (this._observableInstanceState === 0 /* UNINITIALIZED */) {
|
|
2076
|
+
if (this._observableInstanceState === 0 /* ObservableInstanceLifecycle.UNINITIALIZED */) {
|
|
2069
2077
|
return;
|
|
2070
2078
|
}
|
|
2071
2079
|
this.getChildren().forEach(function (node) {
|
|
@@ -2074,8 +2082,8 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
2074
2082
|
// beforeDestroy should run before the disposers since else we could end up in a situation where
|
|
2075
2083
|
// a disposer added with addDisposer at this stage (beforeDestroy) is actually never released
|
|
2076
2084
|
this.baseAboutToDie();
|
|
2077
|
-
this._internalEventsEmit("dispose" /* Dispose */);
|
|
2078
|
-
this._internalEventsClear("dispose" /* Dispose */);
|
|
2085
|
+
this._internalEventsEmit("dispose" /* InternalEvents.Dispose */);
|
|
2086
|
+
this._internalEventsClear("dispose" /* InternalEvents.Dispose */);
|
|
2079
2087
|
}
|
|
2080
2088
|
});
|
|
2081
2089
|
Object.defineProperty(ObjectNode.prototype, "finalizeDeath", {
|
|
@@ -2101,7 +2109,7 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
2101
2109
|
writable: true,
|
|
2102
2110
|
value: function (onChange) {
|
|
2103
2111
|
this._addSnapshotReaction();
|
|
2104
|
-
return this._internalEventsRegister("snapshot" /* Snapshot */, onChange);
|
|
2112
|
+
return this._internalEventsRegister("snapshot" /* InternalEvents.Snapshot */, onChange);
|
|
2105
2113
|
}
|
|
2106
2114
|
});
|
|
2107
2115
|
Object.defineProperty(ObjectNode.prototype, "emitSnapshot", {
|
|
@@ -2109,7 +2117,7 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
2109
2117
|
configurable: true,
|
|
2110
2118
|
writable: true,
|
|
2111
2119
|
value: function (snapshot) {
|
|
2112
|
-
this._internalEventsEmit("snapshot" /* Snapshot */, snapshot);
|
|
2120
|
+
this._internalEventsEmit("snapshot" /* InternalEvents.Snapshot */, snapshot);
|
|
2113
2121
|
}
|
|
2114
2122
|
});
|
|
2115
2123
|
Object.defineProperty(ObjectNode.prototype, "onPatch", {
|
|
@@ -2117,7 +2125,7 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
2117
2125
|
configurable: true,
|
|
2118
2126
|
writable: true,
|
|
2119
2127
|
value: function (handler) {
|
|
2120
|
-
return this._internalEventsRegister("patch" /* Patch */, handler);
|
|
2128
|
+
return this._internalEventsRegister("patch" /* InternalEvents.Patch */, handler);
|
|
2121
2129
|
}
|
|
2122
2130
|
});
|
|
2123
2131
|
Object.defineProperty(ObjectNode.prototype, "emitPatch", {
|
|
@@ -2125,12 +2133,12 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
2125
2133
|
configurable: true,
|
|
2126
2134
|
writable: true,
|
|
2127
2135
|
value: function (basePatch, source) {
|
|
2128
|
-
if (this._internalEventsHasSubscribers("patch" /* Patch */)) {
|
|
2136
|
+
if (this._internalEventsHasSubscribers("patch" /* InternalEvents.Patch */)) {
|
|
2129
2137
|
var localizedPatch = extend({}, basePatch, {
|
|
2130
2138
|
path: source.path.substr(this.path.length) + "/" + basePatch.path // calculate the relative path of the patch
|
|
2131
2139
|
});
|
|
2132
2140
|
var _a = __read(splitPatch(localizedPatch), 2), patch = _a[0], reversePatch = _a[1];
|
|
2133
|
-
this._internalEventsEmit("patch" /* Patch */, patch, reversePatch);
|
|
2141
|
+
this._internalEventsEmit("patch" /* InternalEvents.Patch */, patch, reversePatch);
|
|
2134
2142
|
}
|
|
2135
2143
|
if (this.parent)
|
|
2136
2144
|
this.parent.emitPatch(basePatch, source);
|
|
@@ -2141,7 +2149,7 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
2141
2149
|
configurable: true,
|
|
2142
2150
|
writable: true,
|
|
2143
2151
|
value: function (disposer) {
|
|
2144
|
-
return this._internalEventsHas("dispose" /* Dispose */, disposer);
|
|
2152
|
+
return this._internalEventsHas("dispose" /* InternalEvents.Dispose */, disposer);
|
|
2145
2153
|
}
|
|
2146
2154
|
});
|
|
2147
2155
|
Object.defineProperty(ObjectNode.prototype, "addDisposer", {
|
|
@@ -2150,7 +2158,7 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
2150
2158
|
writable: true,
|
|
2151
2159
|
value: function (disposer) {
|
|
2152
2160
|
if (!this.hasDisposer(disposer)) {
|
|
2153
|
-
this._internalEventsRegister("dispose" /* Dispose */, disposer, true);
|
|
2161
|
+
this._internalEventsRegister("dispose" /* InternalEvents.Dispose */, disposer, true);
|
|
2154
2162
|
return;
|
|
2155
2163
|
}
|
|
2156
2164
|
throw fail("cannot add a disposer when it is already registered for execution");
|
|
@@ -2161,10 +2169,10 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
2161
2169
|
configurable: true,
|
|
2162
2170
|
writable: true,
|
|
2163
2171
|
value: function (disposer) {
|
|
2164
|
-
if (!this._internalEventsHas("dispose" /* Dispose */, disposer)) {
|
|
2172
|
+
if (!this._internalEventsHas("dispose" /* InternalEvents.Dispose */, disposer)) {
|
|
2165
2173
|
throw fail("cannot remove a disposer which was never registered for execution");
|
|
2166
2174
|
}
|
|
2167
|
-
this._internalEventsUnregister("dispose" /* Dispose */, disposer);
|
|
2175
|
+
this._internalEventsUnregister("dispose" /* InternalEvents.Dispose */, disposer);
|
|
2168
2176
|
}
|
|
2169
2177
|
});
|
|
2170
2178
|
Object.defineProperty(ObjectNode.prototype, "removeMiddleware", {
|
|
@@ -2272,7 +2280,7 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
2272
2280
|
args[_i - 1] = arguments[_i];
|
|
2273
2281
|
}
|
|
2274
2282
|
if (this._internalEvents) {
|
|
2275
|
-
(_a = this._internalEvents).emit.apply(_a,
|
|
2283
|
+
(_a = this._internalEvents).emit.apply(_a, __spreadArray([event], __read(args), false));
|
|
2276
2284
|
}
|
|
2277
2285
|
}
|
|
2278
2286
|
});
|
|
@@ -2915,11 +2923,11 @@ function serializeArgument(node, actionName, index, arg) {
|
|
|
2915
2923
|
// 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
|
|
2916
2924
|
// 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
|
|
2917
2925
|
if (isStateTreeNode(arg))
|
|
2918
|
-
return serializeTheUnserializable("[MSTNode: "
|
|
2926
|
+
return serializeTheUnserializable("[MSTNode: ".concat(getType(arg).name, "]"));
|
|
2919
2927
|
if (typeof arg === "function")
|
|
2920
2928
|
return serializeTheUnserializable("[function]");
|
|
2921
2929
|
if (typeof arg === "object" && !isPlainObject(arg) && !isArray(arg))
|
|
2922
|
-
return serializeTheUnserializable("[object "
|
|
2930
|
+
return serializeTheUnserializable("[object ".concat((arg && arg.constructor && arg.constructor.name) || "Complex Object", "]"));
|
|
2923
2931
|
try {
|
|
2924
2932
|
// Check if serializable, cycle free etc...
|
|
2925
2933
|
// MWE: there must be a better way....
|
|
@@ -2960,7 +2968,7 @@ function applyAction(target, actions) {
|
|
|
2960
2968
|
function baseApplyAction(target, action) {
|
|
2961
2969
|
var resolvedTarget = tryResolve(target, action.path || "");
|
|
2962
2970
|
if (!resolvedTarget)
|
|
2963
|
-
throw fail("Invalid action path: "
|
|
2971
|
+
throw fail("Invalid action path: ".concat(action.path || ""));
|
|
2964
2972
|
var node = getStateTreeNode(resolvedTarget);
|
|
2965
2973
|
// Reserved functions
|
|
2966
2974
|
if (action.name === "@APPLY_PATCHES") {
|
|
@@ -2970,7 +2978,7 @@ function baseApplyAction(target, action) {
|
|
|
2970
2978
|
return applySnapshot.call(null, resolvedTarget, action.args[0]);
|
|
2971
2979
|
}
|
|
2972
2980
|
if (!(typeof resolvedTarget[action.name] === "function"))
|
|
2973
|
-
throw fail("Action '"
|
|
2981
|
+
throw fail("Action '".concat(action.name, "' does not exist in '").concat(node.path, "'"));
|
|
2974
2982
|
return resolvedTarget[action.name].apply(resolvedTarget, action.args ? action.args.map(function (v) { return deserializeArgument(node, v); }) : []);
|
|
2975
2983
|
}
|
|
2976
2984
|
/**
|
|
@@ -3175,7 +3183,7 @@ function createActionInvoker(target, name, fn) {
|
|
|
3175
3183
|
tree: getRoot(target),
|
|
3176
3184
|
rootId: parentContext ? parentContext.rootId : id,
|
|
3177
3185
|
parentId: parentContext ? parentContext.id : 0,
|
|
3178
|
-
allParentIds: parentContext ?
|
|
3186
|
+
allParentIds: parentContext ? __spreadArray(__spreadArray([], __read(parentContext.allParentIds), false), [parentContext.id], false) : [],
|
|
3179
3187
|
parentEvent: parentContext,
|
|
3180
3188
|
parentActionEvent: parentActionContext
|
|
3181
3189
|
}, fn);
|
|
@@ -3331,11 +3339,11 @@ function runMiddleWares(node, baseCall, originalFn) {
|
|
|
3331
3339
|
if (devMode()) {
|
|
3332
3340
|
if (!nextInvoked && !abortInvoked) {
|
|
3333
3341
|
var node2 = getStateTreeNode(call.tree);
|
|
3334
|
-
throw fail("Neither the next() nor the abort() callback within the middleware "
|
|
3342
|
+
throw fail("Neither the next() nor the abort() callback within the middleware ".concat(handler.name, " for the action: \"").concat(call.name, "\" on the node: ").concat(node2.type.name, " was invoked."));
|
|
3335
3343
|
}
|
|
3336
3344
|
else if (nextInvoked && abortInvoked) {
|
|
3337
3345
|
var node2 = getStateTreeNode(call.tree);
|
|
3338
|
-
throw fail("The next() and abort() callback within the middleware "
|
|
3346
|
+
throw fail("The next() and abort() callback within the middleware ".concat(handler.name, " for the action: \"").concat(call.name, "\" on the node: ").concat(node2.type.name, " were invoked."));
|
|
3339
3347
|
}
|
|
3340
3348
|
}
|
|
3341
3349
|
return result;
|
|
@@ -3385,7 +3393,7 @@ function safeStringify(value) {
|
|
|
3385
3393
|
}
|
|
3386
3394
|
catch (e) {
|
|
3387
3395
|
// istanbul ignore next
|
|
3388
|
-
return "<Unserializable: "
|
|
3396
|
+
return "<Unserializable: ".concat(e, ">");
|
|
3389
3397
|
}
|
|
3390
3398
|
}
|
|
3391
3399
|
/**
|
|
@@ -3394,15 +3402,15 @@ function safeStringify(value) {
|
|
|
3394
3402
|
*/
|
|
3395
3403
|
function prettyPrintValue(value) {
|
|
3396
3404
|
return typeof value === "function"
|
|
3397
|
-
? "<function"
|
|
3405
|
+
? "<function".concat(value.name ? " " + value.name : "", ">")
|
|
3398
3406
|
: isStateTreeNode(value)
|
|
3399
|
-
? "<"
|
|
3400
|
-
: "`"
|
|
3407
|
+
? "<".concat(value, ">")
|
|
3408
|
+
: "`".concat(safeStringify(value), "`");
|
|
3401
3409
|
}
|
|
3402
3410
|
function shortenPrintValue(valueInString) {
|
|
3403
3411
|
return valueInString.length < 280
|
|
3404
3412
|
? valueInString
|
|
3405
|
-
: valueInString.substring(0, 272)
|
|
3413
|
+
: "".concat(valueInString.substring(0, 272), "......").concat(valueInString.substring(valueInString.length - 8));
|
|
3406
3414
|
}
|
|
3407
3415
|
function toErrorString(error) {
|
|
3408
3416
|
var value = error.value;
|
|
@@ -3414,19 +3422,19 @@ function toErrorString(error) {
|
|
|
3414
3422
|
})
|
|
3415
3423
|
.filter(function (path) { return path.length > 0; })
|
|
3416
3424
|
.join("/");
|
|
3417
|
-
var pathPrefix = fullPath.length > 0 ? "at path \"/"
|
|
3425
|
+
var pathPrefix = fullPath.length > 0 ? "at path \"/".concat(fullPath, "\" ") : "";
|
|
3418
3426
|
var currentTypename = isStateTreeNode(value)
|
|
3419
|
-
? "value of type "
|
|
3427
|
+
? "value of type ".concat(getStateTreeNode(value).type.name, ":")
|
|
3420
3428
|
: isPrimitive(value)
|
|
3421
3429
|
? "value"
|
|
3422
3430
|
: "snapshot";
|
|
3423
3431
|
var isSnapshotCompatible = type && isStateTreeNode(value) && type.is(getStateTreeNode(value).snapshot);
|
|
3424
|
-
return (""
|
|
3425
|
-
(error.message ? " ("
|
|
3432
|
+
return ("".concat(pathPrefix).concat(currentTypename, " ").concat(prettyPrintValue(value), " is not assignable ").concat(type ? "to type: `".concat(type.name, "`") : "") +
|
|
3433
|
+
(error.message ? " (".concat(error.message, ")") : "") +
|
|
3426
3434
|
(type
|
|
3427
3435
|
? isPrimitiveType(type) || isPrimitive(value)
|
|
3428
3436
|
? "."
|
|
3429
|
-
: ", expected an instance of `"
|
|
3437
|
+
: ", expected an instance of `".concat(type.name, "` or a snapshot like `").concat(type.describe(), "` instead.") +
|
|
3430
3438
|
(isSnapshotCompatible
|
|
3431
3439
|
? " (Note that a snapshot of the provided value is compatible with the targeted type)"
|
|
3432
3440
|
: "")
|
|
@@ -3489,7 +3497,7 @@ function validationErrorsToString(type, value, errors) {
|
|
|
3489
3497
|
if (errors.length === 0) {
|
|
3490
3498
|
return undefined;
|
|
3491
3499
|
}
|
|
3492
|
-
return ("Error while converting "
|
|
3500
|
+
return ("Error while converting ".concat(shortenPrintValue(prettyPrintValue(value)), " to `").concat(type.name, "`:\n\n ") + errors.map(toErrorString).join("\n "));
|
|
3493
3501
|
}
|
|
3494
3502
|
|
|
3495
3503
|
var identifierCacheId = 0;
|
|
@@ -3537,7 +3545,7 @@ var IdentifierCache = /** @class */ (function () {
|
|
|
3537
3545
|
writable: true,
|
|
3538
3546
|
value: function (identifier) {
|
|
3539
3547
|
var modificationId = this.lastCacheModificationPerId.get(identifier) || 0;
|
|
3540
|
-
return this.cacheId
|
|
3548
|
+
return "".concat(this.cacheId, "-").concat(modificationId);
|
|
3541
3549
|
}
|
|
3542
3550
|
});
|
|
3543
3551
|
Object.defineProperty(IdentifierCache.prototype, "addNodeToCache", {
|
|
@@ -3652,9 +3660,9 @@ var IdentifierCache = /** @class */ (function () {
|
|
|
3652
3660
|
case 1:
|
|
3653
3661
|
return matches[0];
|
|
3654
3662
|
default:
|
|
3655
|
-
throw fail("Cannot resolve a reference to type '"
|
|
3663
|
+
throw fail("Cannot resolve a reference to type '".concat(type.name, "' with id: '").concat(identifier, "' unambigously, there are multiple candidates: ").concat(matches
|
|
3656
3664
|
.map(function (n) { return n.path; })
|
|
3657
|
-
.join(", "));
|
|
3665
|
+
.join(", ")));
|
|
3658
3666
|
}
|
|
3659
3667
|
}
|
|
3660
3668
|
});
|
|
@@ -3670,7 +3678,7 @@ function createObjectNode(type, parent, subpath, environment, initialValue) {
|
|
|
3670
3678
|
if (existingNode) {
|
|
3671
3679
|
if (existingNode.parent) {
|
|
3672
3680
|
// istanbul ignore next
|
|
3673
|
-
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 '"
|
|
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 '".concat(parent ? parent.path : "", "/").concat(subpath, "', but it lives already at '").concat(existingNode.path, "'"));
|
|
3674
3682
|
}
|
|
3675
3683
|
if (parent) {
|
|
3676
3684
|
existingNode.setParent(parent, subpath);
|
|
@@ -3733,7 +3741,7 @@ function assertIsStateTreeNode(value, argNumber) {
|
|
|
3733
3741
|
function getStateTreeNode(value) {
|
|
3734
3742
|
if (!isStateTreeNode(value)) {
|
|
3735
3743
|
// istanbul ignore next
|
|
3736
|
-
throw fail("Value "
|
|
3744
|
+
throw fail("Value ".concat(value, " is no MST Node"));
|
|
3737
3745
|
}
|
|
3738
3746
|
return value.$treenode;
|
|
3739
3747
|
}
|
|
@@ -3759,7 +3767,7 @@ var doubleDot = function (_) { return ".."; };
|
|
|
3759
3767
|
function getRelativePathBetweenNodes(base, target) {
|
|
3760
3768
|
// PRE condition target is (a child of) base!
|
|
3761
3769
|
if (base.root !== target.root) {
|
|
3762
|
-
throw fail("Cannot calculate relative path: objects '"
|
|
3770
|
+
throw fail("Cannot calculate relative path: objects '".concat(base, "' and '").concat(target, "' are not part of the same object tree"));
|
|
3763
3771
|
}
|
|
3764
3772
|
var baseParts = splitJsonPath(base.path);
|
|
3765
3773
|
var targetParts = splitJsonPath(target.path);
|
|
@@ -3816,7 +3824,7 @@ function resolveNodeByPathParts(base, pathParts, failIfResolveFails) {
|
|
|
3816
3824
|
}
|
|
3817
3825
|
}
|
|
3818
3826
|
}
|
|
3819
|
-
throw fail("Could not resolve '"
|
|
3827
|
+
throw fail("Could not resolve '".concat(part, "' in path '").concat(joinJsonPath(pathParts.slice(0, i)) || "/", "' while resolving '").concat(joinJsonPath(pathParts), "'"));
|
|
3820
3828
|
}
|
|
3821
3829
|
}
|
|
3822
3830
|
catch (e) {
|
|
@@ -4136,7 +4144,7 @@ var EventHandler = /** @class */ (function () {
|
|
|
4136
4144
|
}
|
|
4137
4145
|
// make a copy just in case it changes
|
|
4138
4146
|
var handlers = this.handlers.slice();
|
|
4139
|
-
handlers.forEach(function (f) { return f.apply(void 0,
|
|
4147
|
+
handlers.forEach(function (f) { return f.apply(void 0, __spreadArray([], __read(args), false)); });
|
|
4140
4148
|
}
|
|
4141
4149
|
});
|
|
4142
4150
|
return EventHandler;
|
|
@@ -4229,7 +4237,7 @@ var EventHandlers = /** @class */ (function () {
|
|
|
4229
4237
|
}
|
|
4230
4238
|
var handler = this.eventHandlers && this.eventHandlers[event];
|
|
4231
4239
|
if (handler) {
|
|
4232
|
-
(_a = handler).emit.apply(_a,
|
|
4240
|
+
(_a = handler).emit.apply(_a, __spreadArray([], __read(args), false));
|
|
4233
4241
|
}
|
|
4234
4242
|
}
|
|
4235
4243
|
});
|
|
@@ -4274,7 +4282,7 @@ deprecated.ids = {};
|
|
|
4274
4282
|
* @hidden
|
|
4275
4283
|
*/
|
|
4276
4284
|
function warnError(msg) {
|
|
4277
|
-
console.warn(new Error("[mobx-state-tree] "
|
|
4285
|
+
console.warn(new Error("[mobx-state-tree] ".concat(msg)));
|
|
4278
4286
|
}
|
|
4279
4287
|
/**
|
|
4280
4288
|
* @internal
|
|
@@ -4299,7 +4307,7 @@ function assertArg(value, fn, typeName, argNumber) {
|
|
|
4299
4307
|
if (devMode()) {
|
|
4300
4308
|
if (!fn(value)) {
|
|
4301
4309
|
// istanbul ignore next
|
|
4302
|
-
throw fail("expected "
|
|
4310
|
+
throw fail("expected ".concat(typeName, " as argument ").concat(asArray(argNumber).join(" or "), ", got ").concat(value, " instead"));
|
|
4303
4311
|
}
|
|
4304
4312
|
}
|
|
4305
4313
|
}
|
|
@@ -4317,10 +4325,10 @@ function assertIsFunction(value, argNumber) {
|
|
|
4317
4325
|
function assertIsNumber(value, argNumber, min, max) {
|
|
4318
4326
|
assertArg(value, function (n) { return typeof n === "number"; }, "number", argNumber);
|
|
4319
4327
|
if (min !== undefined) {
|
|
4320
|
-
assertArg(value, function (n) { return n >= min; }, "number greater than "
|
|
4328
|
+
assertArg(value, function (n) { return n >= min; }, "number greater than ".concat(min), argNumber);
|
|
4321
4329
|
}
|
|
4322
4330
|
if (max !== undefined) {
|
|
4323
|
-
assertArg(value, function (n) { return n <= max; }, "number lesser than "
|
|
4331
|
+
assertArg(value, function (n) { return n <= max; }, "number lesser than ".concat(max), argNumber);
|
|
4324
4332
|
}
|
|
4325
4333
|
}
|
|
4326
4334
|
/**
|
|
@@ -4399,7 +4407,7 @@ function toGeneratorFunction(p) {
|
|
|
4399
4407
|
}
|
|
4400
4408
|
return __generator(this, function (_a) {
|
|
4401
4409
|
switch (_a.label) {
|
|
4402
|
-
case 0: return [4 /*yield*/, p.apply(void 0,
|
|
4410
|
+
case 0: return [4 /*yield*/, p.apply(void 0, __spreadArray([], __read(args), false))];
|
|
4403
4411
|
case 1: return [2 /*return*/, (_a.sent())];
|
|
4404
4412
|
}
|
|
4405
4413
|
});
|
|
@@ -4456,7 +4464,7 @@ function createFlowSpawner(name, generator) {
|
|
|
4456
4464
|
tree: parentContext.tree,
|
|
4457
4465
|
context: parentContext.context,
|
|
4458
4466
|
parentId: parentContext.id,
|
|
4459
|
-
allParentIds:
|
|
4467
|
+
allParentIds: __spreadArray(__spreadArray([], __read(parentContext.allParentIds), false), [parentContext.id], false),
|
|
4460
4468
|
rootId: parentContext.rootId,
|
|
4461
4469
|
parentEvent: parentContext,
|
|
4462
4470
|
parentActionEvent: parentActionContext
|
|
@@ -4636,7 +4644,7 @@ function splitJsonPath(path) {
|
|
|
4636
4644
|
stringStartsWith(path, "./") ||
|
|
4637
4645
|
stringStartsWith(path, "../");
|
|
4638
4646
|
if (!valid) {
|
|
4639
|
-
throw fail("a json path must be either rooted, empty or relative, but got '"
|
|
4647
|
+
throw fail("a json path must be either rooted, empty or relative, but got '".concat(path, "'"));
|
|
4640
4648
|
}
|
|
4641
4649
|
// '/a/b/c' -> ["a", "b", "c"]
|
|
4642
4650
|
// '../../b/c' -> ["..", "..", "b", "c"]
|
|
@@ -4682,7 +4690,7 @@ var SnapshotProcessor = /** @class */ (function (_super) {
|
|
|
4682
4690
|
configurable: true,
|
|
4683
4691
|
writable: true,
|
|
4684
4692
|
value: function () {
|
|
4685
|
-
return "snapshotProcessor("
|
|
4693
|
+
return "snapshotProcessor(".concat(this._subtype.describe(), ")");
|
|
4686
4694
|
}
|
|
4687
4695
|
});
|
|
4688
4696
|
Object.defineProperty(SnapshotProcessor.prototype, "preProcessSnapshot", {
|
|
@@ -5098,7 +5106,7 @@ var MapType = /** @class */ (function (_super) {
|
|
|
5098
5106
|
if (!type.identifierAttribute)
|
|
5099
5107
|
return current;
|
|
5100
5108
|
if (current && current !== type.identifierAttribute) {
|
|
5101
|
-
throw fail("The objects in a map should all have the same identifier attribute, expected '"
|
|
5109
|
+
throw fail("The objects in a map should all have the same identifier attribute, expected '".concat(current, "', but child of type '").concat(type.name, "' declared attribute '").concat(type.identifierAttribute, "' as identifier"));
|
|
5102
5110
|
}
|
|
5103
5111
|
return type.identifierAttribute;
|
|
5104
5112
|
}, undefined);
|
|
@@ -5222,7 +5230,7 @@ var MapType = /** @class */ (function (_super) {
|
|
|
5222
5230
|
if (this.identifierMode === MapIdentifierMode.YES && node instanceof ObjectNode) {
|
|
5223
5231
|
var identifier = node.identifier;
|
|
5224
5232
|
if (identifier !== expected)
|
|
5225
|
-
throw fail("A map of objects containing an identifier should always store the object under their own identifier. Trying to store key '"
|
|
5233
|
+
throw fail("A map of objects containing an identifier should always store the object under their own identifier. Trying to store key '".concat(identifier, "', but expected: '").concat(expected, "'"));
|
|
5226
5234
|
}
|
|
5227
5235
|
}
|
|
5228
5236
|
});
|
|
@@ -5394,7 +5402,7 @@ MapType.prototype.applySnapshot = mobx.action(MapType.prototype.applySnapshot);
|
|
|
5394
5402
|
* @returns
|
|
5395
5403
|
*/
|
|
5396
5404
|
function map(subtype) {
|
|
5397
|
-
return new MapType("Map<string, "
|
|
5405
|
+
return new MapType("Map<string, ".concat(subtype.name, ">"), subtype);
|
|
5398
5406
|
}
|
|
5399
5407
|
/**
|
|
5400
5408
|
* Returns if a given value represents a map type.
|
|
@@ -5711,7 +5719,7 @@ ArrayType.prototype.applySnapshot = mobx.action(ArrayType.prototype.applySnapsho
|
|
|
5711
5719
|
*/
|
|
5712
5720
|
function array(subtype) {
|
|
5713
5721
|
assertIsType(subtype, 1);
|
|
5714
|
-
return new ArrayType(subtype.name
|
|
5722
|
+
return new ArrayType("".concat(subtype.name, "[]"), subtype);
|
|
5715
5723
|
}
|
|
5716
5724
|
function reconcileArrayChildren(parent, childType, oldNodes, newValues, newPaths) {
|
|
5717
5725
|
var nothingChanged = true;
|
|
@@ -5745,7 +5753,7 @@ function reconcileArrayChildren(parent, childType, oldNodes, newValues, newPaths
|
|
|
5745
5753
|
// check if already belongs to the same parent. if so, avoid pushing item in. only swapping can occur.
|
|
5746
5754
|
if (isStateTreeNode(newValue) && getStateTreeNode(newValue).parent === parent) {
|
|
5747
5755
|
// this node is owned by this parent, but not in the reconcilable set, so it must be double
|
|
5748
|
-
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 '"
|
|
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 '".concat(parent.path, "/").concat(newPath, "', but it lives already at '").concat(getStateTreeNode(newValue).path, "'"));
|
|
5749
5757
|
}
|
|
5750
5758
|
nothingChanged = false;
|
|
5751
5759
|
var newNode = valueAsNode(childType, parent, newPath, newValue);
|
|
@@ -5861,7 +5869,7 @@ function toPropertiesObject(declaredProps) {
|
|
|
5861
5869
|
var alreadySeenKeys = new Set();
|
|
5862
5870
|
keysList.forEach(function (key) {
|
|
5863
5871
|
if (alreadySeenKeys.has(key)) {
|
|
5864
|
-
throw fail(key
|
|
5872
|
+
throw fail("".concat(key, " is declared twice in the model. Model should not contain the same keys"));
|
|
5865
5873
|
}
|
|
5866
5874
|
alreadySeenKeys.add(key);
|
|
5867
5875
|
});
|
|
@@ -5869,7 +5877,7 @@ function toPropertiesObject(declaredProps) {
|
|
|
5869
5877
|
return keysList.reduce(function (props, key) {
|
|
5870
5878
|
// warn if user intended a HOOK
|
|
5871
5879
|
if (key in Hook) {
|
|
5872
|
-
throw fail("Hook '"
|
|
5880
|
+
throw fail("Hook '".concat(key, "' was defined as property. Hooks should be defined as part of the actions"));
|
|
5873
5881
|
}
|
|
5874
5882
|
// the user intended to use a view
|
|
5875
5883
|
var descriptor = Object.getOwnPropertyDescriptor(declaredProps, key);
|
|
@@ -5896,14 +5904,14 @@ function toPropertiesObject(declaredProps) {
|
|
|
5896
5904
|
else if (isType(value)) ;
|
|
5897
5905
|
// its a function, maybe the user wanted a view?
|
|
5898
5906
|
else if (devMode() && typeof value === "function") {
|
|
5899
|
-
throw fail("Invalid type definition for property '"
|
|
5907
|
+
throw fail("Invalid type definition for property '".concat(key, "', it looks like you passed a function. Did you forget to invoke it, or did you intend to declare a view / action?"));
|
|
5900
5908
|
}
|
|
5901
5909
|
// no other complex values
|
|
5902
5910
|
else if (devMode() && typeof value === "object") {
|
|
5903
|
-
throw fail("Invalid type definition for property '"
|
|
5911
|
+
throw fail("Invalid type definition for property '".concat(key, "', it looks like you passed an object. Try passing another model type or a types.frozen."));
|
|
5904
5912
|
}
|
|
5905
5913
|
else {
|
|
5906
|
-
throw fail("Invalid type definition for property '"
|
|
5914
|
+
throw fail("Invalid type definition for property '".concat(key, "', cannot infer a type from a value like '").concat(value, "' (").concat(typeof value, ")"));
|
|
5907
5915
|
}
|
|
5908
5916
|
return props;
|
|
5909
5917
|
}, declaredProps);
|
|
@@ -6016,7 +6024,7 @@ var ModelType = /** @class */ (function (_super) {
|
|
|
6016
6024
|
this.forAllProps(function (propName, propType) {
|
|
6017
6025
|
if (propType.flags & TypeFlags.Identifier) {
|
|
6018
6026
|
if (identifierAttribute)
|
|
6019
|
-
throw fail("Cannot define property '"
|
|
6027
|
+
throw fail("Cannot define property '".concat(propName, "' as object identifier, property '").concat(identifierAttribute, "' is already defined as identifier property"));
|
|
6020
6028
|
identifierAttribute = propName;
|
|
6021
6029
|
}
|
|
6022
6030
|
});
|
|
@@ -6062,10 +6070,10 @@ var ModelType = /** @class */ (function (_super) {
|
|
|
6062
6070
|
Object.keys(actions).forEach(function (name) {
|
|
6063
6071
|
// warn if preprocessor was given
|
|
6064
6072
|
if (name === PRE_PROCESS_SNAPSHOT)
|
|
6065
|
-
throw fail("Cannot define action '"
|
|
6073
|
+
throw fail("Cannot define action '".concat(PRE_PROCESS_SNAPSHOT, "', it should be defined using 'type.preProcessSnapshot(fn)' instead"));
|
|
6066
6074
|
// warn if postprocessor was given
|
|
6067
6075
|
if (name === POST_PROCESS_SNAPSHOT)
|
|
6068
|
-
throw fail("Cannot define action '"
|
|
6076
|
+
throw fail("Cannot define action '".concat(POST_PROCESS_SNAPSHOT, "', it should be defined using 'type.postProcessSnapshot(fn)' instead"));
|
|
6069
6077
|
var action2 = actions[name];
|
|
6070
6078
|
// apply hook composition
|
|
6071
6079
|
var baseAction = self[name];
|
|
@@ -6095,7 +6103,7 @@ var ModelType = /** @class */ (function (_super) {
|
|
|
6095
6103
|
value: function (fn) {
|
|
6096
6104
|
var _this = this;
|
|
6097
6105
|
if (typeof fn !== "function") {
|
|
6098
|
-
throw fail("You passed an "
|
|
6106
|
+
throw fail("You passed an ".concat(typeof fn, " to volatile state as an argument, when function is expected"));
|
|
6099
6107
|
}
|
|
6100
6108
|
var stateInitializer = function (self) {
|
|
6101
6109
|
_this.instantiateVolatileState(self, fn(self));
|
|
@@ -6124,7 +6132,7 @@ var ModelType = /** @class */ (function (_super) {
|
|
|
6124
6132
|
var initializer = function (self) {
|
|
6125
6133
|
var _a = fn(self), actions = _a.actions, views = _a.views, state = _a.state, rest = __rest(_a, ["actions", "views", "state"]);
|
|
6126
6134
|
for (var key in rest)
|
|
6127
|
-
throw fail("The `extend` function should return an object with a subset of the fields 'actions', 'views' and 'state'. Found invalid key '"
|
|
6135
|
+
throw fail("The `extend` function should return an object with a subset of the fields 'actions', 'views' and 'state'. Found invalid key '".concat(key, "'"));
|
|
6128
6136
|
if (state)
|
|
6129
6137
|
_this.instantiateVolatileState(self, state);
|
|
6130
6138
|
if (views)
|
|
@@ -6308,7 +6316,7 @@ var ModelType = /** @class */ (function (_super) {
|
|
|
6308
6316
|
atom.reportObserved();
|
|
6309
6317
|
}
|
|
6310
6318
|
catch (e) {
|
|
6311
|
-
throw fail(name
|
|
6319
|
+
throw fail("".concat(name, " property is declared twice"));
|
|
6312
6320
|
}
|
|
6313
6321
|
res[name] = _this.getChildNode(node, name).snapshot;
|
|
6314
6322
|
});
|
|
@@ -6336,7 +6344,7 @@ var ModelType = /** @class */ (function (_super) {
|
|
|
6336
6344
|
writable: true,
|
|
6337
6345
|
value: function (node, subpath, patch) {
|
|
6338
6346
|
if (!(patch.op === "replace" || patch.op === "add")) {
|
|
6339
|
-
throw fail("object does not support operation "
|
|
6347
|
+
throw fail("object does not support operation ".concat(patch.op));
|
|
6340
6348
|
}
|
|
6341
6349
|
node.storedValue[subpath] = patch.value;
|
|
6342
6350
|
}
|
|
@@ -6568,7 +6576,7 @@ var CoreType = /** @class */ (function (_super) {
|
|
|
6568
6576
|
return typeCheckSuccess();
|
|
6569
6577
|
}
|
|
6570
6578
|
var typeName = this.name === "Date" ? "Date or a unix milliseconds timestamp" : this.name;
|
|
6571
|
-
return typeCheckFailure(context, value, "Value is not a "
|
|
6579
|
+
return typeCheckFailure(context, value, "Value is not a ".concat(typeName));
|
|
6572
6580
|
}
|
|
6573
6581
|
});
|
|
6574
6582
|
return CoreType;
|
|
@@ -6761,7 +6769,7 @@ var Literal = /** @class */ (function (_super) {
|
|
|
6761
6769
|
if (isPrimitive(value) && value === this.value) {
|
|
6762
6770
|
return typeCheckSuccess();
|
|
6763
6771
|
}
|
|
6764
|
-
return typeCheckFailure(context, value, "Value is not a literal "
|
|
6772
|
+
return typeCheckFailure(context, value, "Value is not a literal ".concat(JSON.stringify(this.value)));
|
|
6765
6773
|
}
|
|
6766
6774
|
});
|
|
6767
6775
|
return Literal;
|
|
@@ -6943,7 +6951,7 @@ function enumeration(name, options) {
|
|
|
6943
6951
|
assertIsString(option, i + 1);
|
|
6944
6952
|
});
|
|
6945
6953
|
}
|
|
6946
|
-
var type = union.apply(void 0,
|
|
6954
|
+
var type = union.apply(void 0, __spreadArray([], __read(realOptions.map(function (option) { return literal("" + option); })), false));
|
|
6947
6955
|
if (typeof name === "string")
|
|
6948
6956
|
type.name = name;
|
|
6949
6957
|
return type;
|
|
@@ -7039,7 +7047,7 @@ var Union = /** @class */ (function (_super) {
|
|
|
7039
7047
|
if (this._dispatcher) {
|
|
7040
7048
|
return this._dispatcher(value);
|
|
7041
7049
|
}
|
|
7042
|
-
// find the most
|
|
7050
|
+
// find the most accommodating type
|
|
7043
7051
|
// if we are using reconciliation try the current node type first (fix for #1045)
|
|
7044
7052
|
if (reconcileCurrentType) {
|
|
7045
7053
|
if (reconcileCurrentType.is(value)) {
|
|
@@ -7103,7 +7111,7 @@ function union(optionsOrType) {
|
|
|
7103
7111
|
otherTypes[_i - 1] = arguments[_i];
|
|
7104
7112
|
}
|
|
7105
7113
|
var options = isType(optionsOrType) ? undefined : optionsOrType;
|
|
7106
|
-
var types = isType(optionsOrType) ?
|
|
7114
|
+
var types = isType(optionsOrType) ? __spreadArray([optionsOrType], __read(otherTypes), false) : otherTypes;
|
|
7107
7115
|
var name = "(" + types.map(function (type) { return type.name; }).join(" | ") + ")";
|
|
7108
7116
|
// check all options
|
|
7109
7117
|
if (devMode()) {
|
|
@@ -7465,7 +7473,7 @@ var Late = /** @class */ (function (_super) {
|
|
|
7465
7473
|
* @returns
|
|
7466
7474
|
*/
|
|
7467
7475
|
function late(nameOrType, maybeType) {
|
|
7468
|
-
var name = typeof nameOrType === "string" ? nameOrType : "late("
|
|
7476
|
+
var name = typeof nameOrType === "string" ? nameOrType : "late(".concat(nameOrType.toString(), ")");
|
|
7469
7477
|
var type = typeof nameOrType === "string" ? maybeType : nameOrType;
|
|
7470
7478
|
// checks that the type is actually a late type
|
|
7471
7479
|
if (devMode()) {
|
|
@@ -7537,7 +7545,7 @@ var Lazy = /** @class */ (function (_super) {
|
|
|
7537
7545
|
node.parent.applyPatches([
|
|
7538
7546
|
{
|
|
7539
7547
|
op: "replace",
|
|
7540
|
-
path: "/"
|
|
7548
|
+
path: "/".concat(node.subpath),
|
|
7541
7549
|
value: node.snapshot
|
|
7542
7550
|
}
|
|
7543
7551
|
]);
|
|
@@ -7551,7 +7559,7 @@ var Lazy = /** @class */ (function (_super) {
|
|
|
7551
7559
|
configurable: true,
|
|
7552
7560
|
writable: true,
|
|
7553
7561
|
value: function () {
|
|
7554
|
-
return "<lazy "
|
|
7562
|
+
return "<lazy ".concat(this.name, ">");
|
|
7555
7563
|
}
|
|
7556
7564
|
});
|
|
7557
7565
|
Object.defineProperty(Lazy.prototype, "instantiate", {
|
|
@@ -7605,7 +7613,7 @@ var Lazy = /** @class */ (function (_super) {
|
|
|
7605
7613
|
var Frozen = /** @class */ (function (_super) {
|
|
7606
7614
|
__extends(Frozen, _super);
|
|
7607
7615
|
function Frozen(subType) {
|
|
7608
|
-
var _this = _super.call(this, subType ? "frozen("
|
|
7616
|
+
var _this = _super.call(this, subType ? "frozen(".concat(subType.name, ")") : "frozen") || this;
|
|
7609
7617
|
Object.defineProperty(_this, "subType", {
|
|
7610
7618
|
enumerable: true,
|
|
7611
7619
|
configurable: true,
|
|
@@ -7761,7 +7769,7 @@ var StoredReference = /** @class */ (function () {
|
|
|
7761
7769
|
this.identifier = id;
|
|
7762
7770
|
}
|
|
7763
7771
|
else {
|
|
7764
|
-
throw fail("Can only store references to tree nodes or identifiers, got: '"
|
|
7772
|
+
throw fail("Can only store references to tree nodes or identifiers, got: '".concat(value, "'"));
|
|
7765
7773
|
}
|
|
7766
7774
|
}
|
|
7767
7775
|
Object.defineProperty(StoredReference.prototype, "updateResolvedReference", {
|
|
@@ -7778,7 +7786,7 @@ var StoredReference = /** @class */ (function () {
|
|
|
7778
7786
|
// reference was initialized with the identifier of the target
|
|
7779
7787
|
var target = root.identifierCache.resolve(targetType, normalizedId);
|
|
7780
7788
|
if (!target) {
|
|
7781
|
-
throw new InvalidReferenceError("[mobx-state-tree] Failed to resolve reference '"
|
|
7789
|
+
throw new InvalidReferenceError("[mobx-state-tree] Failed to resolve reference '".concat(this.identifier, "' to type '").concat(this.targetType.name, "' (from node: ").concat(node.path, ")"));
|
|
7782
7790
|
}
|
|
7783
7791
|
this.resolvedReference = {
|
|
7784
7792
|
node: target,
|
|
@@ -7817,7 +7825,7 @@ var InvalidReferenceError = /** @class */ (function (_super) {
|
|
|
7817
7825
|
var BaseReferenceType = /** @class */ (function (_super) {
|
|
7818
7826
|
__extends(BaseReferenceType, _super);
|
|
7819
7827
|
function BaseReferenceType(targetType, onInvalidated) {
|
|
7820
|
-
var _this = _super.call(this, "reference("
|
|
7828
|
+
var _this = _super.call(this, "reference(".concat(targetType.name, ")")) || this;
|
|
7821
7829
|
Object.defineProperty(_this, "targetType", {
|
|
7822
7830
|
enumerable: true,
|
|
7823
7831
|
configurable: true,
|
|
@@ -8242,7 +8250,7 @@ var BaseIdentifierType = /** @class */ (function (_super) {
|
|
|
8242
8250
|
value: function (current, newValue, parent, subpath) {
|
|
8243
8251
|
// we don't consider detaching here since identifier are scalar nodes, and scalar nodes cannot be detached
|
|
8244
8252
|
if (current.storedValue !== newValue)
|
|
8245
|
-
throw fail("Tried to change identifier from '"
|
|
8253
|
+
throw fail("Tried to change identifier from '".concat(current.storedValue, "' to '").concat(newValue, "'. Changing identifiers is not allowed."));
|
|
8246
8254
|
current.setParent(parent, subpath);
|
|
8247
8255
|
return current;
|
|
8248
8256
|
}
|
|
@@ -8253,7 +8261,7 @@ var BaseIdentifierType = /** @class */ (function (_super) {
|
|
|
8253
8261
|
writable: true,
|
|
8254
8262
|
value: function (value, context) {
|
|
8255
8263
|
if (typeof value !== this.validType) {
|
|
8256
|
-
return typeCheckFailure(context, value, "Value is not a valid "
|
|
8264
|
+
return typeCheckFailure(context, value, "Value is not a valid ".concat(this.describe(), ", expected a ").concat(this.validType));
|
|
8257
8265
|
}
|
|
8258
8266
|
return typeCheckSuccess();
|
|
8259
8267
|
}
|
|
@@ -8464,7 +8472,7 @@ var CustomType = /** @class */ (function (_super) {
|
|
|
8464
8472
|
return typeCheckSuccess();
|
|
8465
8473
|
var typeError = this.options.getValidationMessage(value);
|
|
8466
8474
|
if (typeError) {
|
|
8467
|
-
return typeCheckFailure(context, value, "Invalid value for type '"
|
|
8475
|
+
return typeCheckFailure(context, value, "Invalid value for type '".concat(this.name, "': ").concat(typeError));
|
|
8468
8476
|
}
|
|
8469
8477
|
return typeCheckSuccess();
|
|
8470
8478
|
}
|