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
|
@@ -45,7 +45,7 @@ var Hook;
|
|
|
45
45
|
Hook["beforeDestroy"] = "beforeDestroy";
|
|
46
46
|
})(Hook || (Hook = {}));
|
|
47
47
|
|
|
48
|
-
|
|
48
|
+
/******************************************************************************
|
|
49
49
|
Copyright (c) Microsoft Corporation.
|
|
50
50
|
|
|
51
51
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
@@ -59,7 +59,7 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
|
59
59
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
60
60
|
PERFORMANCE OF THIS SOFTWARE.
|
|
61
61
|
***************************************************************************** */
|
|
62
|
-
/* global Reflect, Promise */
|
|
62
|
+
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
63
63
|
|
|
64
64
|
var extendStatics = function(d, b) {
|
|
65
65
|
extendStatics = Object.setPrototypeOf ||
|
|
@@ -105,7 +105,7 @@ function __generator(thisArg, body) {
|
|
|
105
105
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
106
106
|
function step(op) {
|
|
107
107
|
if (f) throw new TypeError("Generator is already executing.");
|
|
108
|
-
while (_) try {
|
|
108
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
109
109
|
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;
|
|
110
110
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
111
111
|
switch (op[0]) {
|
|
@@ -156,12 +156,20 @@ function __read(o, n) {
|
|
|
156
156
|
return ar;
|
|
157
157
|
}
|
|
158
158
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
}
|
|
159
|
+
function __spreadArray(to, from, pack) {
|
|
160
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
161
|
+
if (ar || !(i in from)) {
|
|
162
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
163
|
+
ar[i] = from[i];
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
170
|
+
var e = new Error(message);
|
|
171
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
172
|
+
};
|
|
165
173
|
|
|
166
174
|
/**
|
|
167
175
|
* Returns the _actual_ type of the given tree node. (Or throws)
|
|
@@ -459,7 +467,7 @@ function getParent(target, depth) {
|
|
|
459
467
|
return parent.storedValue;
|
|
460
468
|
parent = parent.parent;
|
|
461
469
|
}
|
|
462
|
-
throw fail("Failed to find the parent of "
|
|
470
|
+
throw fail("Failed to find the parent of ".concat(getStateTreeNode(target), " at depth ").concat(depth));
|
|
463
471
|
}
|
|
464
472
|
/**
|
|
465
473
|
* 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
|
|
@@ -497,7 +505,7 @@ function getParentOfType(target, type) {
|
|
|
497
505
|
return parent.storedValue;
|
|
498
506
|
parent = parent.parent;
|
|
499
507
|
}
|
|
500
|
-
throw fail("Failed to find the parent of "
|
|
508
|
+
throw fail("Failed to find the parent of ".concat(getStateTreeNode(target), " of a given type"));
|
|
501
509
|
}
|
|
502
510
|
/**
|
|
503
511
|
* Given an object in a model tree, returns the root object of that tree.
|
|
@@ -1352,7 +1360,7 @@ var ScalarNode = /** @class */ (function (_super) {
|
|
|
1352
1360
|
writable: true,
|
|
1353
1361
|
value: function () {
|
|
1354
1362
|
var path = (this.isAlive ? this.path : this.pathUponDeath) || "<root>";
|
|
1355
|
-
return this.type.name
|
|
1363
|
+
return "".concat(this.type.name, "@").concat(path).concat(this.isAlive ? "" : " [dead]");
|
|
1356
1364
|
}
|
|
1357
1365
|
});
|
|
1358
1366
|
Object.defineProperty(ScalarNode.prototype, "die", {
|
|
@@ -1498,7 +1506,7 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
1498
1506
|
enumerable: true,
|
|
1499
1507
|
configurable: true,
|
|
1500
1508
|
writable: true,
|
|
1501
|
-
value: 0 /* UNINITIALIZED */
|
|
1509
|
+
value: 0 /* ObservableInstanceLifecycle.UNINITIALIZED */
|
|
1502
1510
|
});
|
|
1503
1511
|
Object.defineProperty(_this, "_childNodes", {
|
|
1504
1512
|
enumerable: true,
|
|
@@ -1565,7 +1573,7 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
1565
1573
|
}
|
|
1566
1574
|
}
|
|
1567
1575
|
if (typeof id !== "string" && typeof id !== "number") {
|
|
1568
|
-
throw fail("Instance identifier '"
|
|
1576
|
+
throw fail("Instance identifier '".concat(_this.identifierAttribute, "' for type '").concat(_this.type.name, "' must be a string or a number"));
|
|
1569
1577
|
}
|
|
1570
1578
|
// normalize internal identifier to string
|
|
1571
1579
|
_this.identifier = normalizeIdentifier(id);
|
|
@@ -1603,7 +1611,7 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
1603
1611
|
writable: true,
|
|
1604
1612
|
value: function (fireHooks) {
|
|
1605
1613
|
if (fireHooks === void 0) { fireHooks = true; }
|
|
1606
|
-
if (this._observableInstanceState === 0 /* UNINITIALIZED */) {
|
|
1614
|
+
if (this._observableInstanceState === 0 /* ObservableInstanceLifecycle.UNINITIALIZED */) {
|
|
1607
1615
|
this.createObservableInstance(fireHooks);
|
|
1608
1616
|
}
|
|
1609
1617
|
}
|
|
@@ -1621,7 +1629,7 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
1621
1629
|
throw fail("assertion failed: the creation of the observable instance must be done on the initializing phase");
|
|
1622
1630
|
}
|
|
1623
1631
|
}
|
|
1624
|
-
this._observableInstanceState = 1 /* CREATING */;
|
|
1632
|
+
this._observableInstanceState = 1 /* ObservableInstanceLifecycle.CREATING */;
|
|
1625
1633
|
// make sure the parent chain is created as well
|
|
1626
1634
|
// array with parent chain from parent to child
|
|
1627
1635
|
var parentChain = [];
|
|
@@ -1631,7 +1639,7 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
1631
1639
|
// this is done to avoid traversing the whole tree to the root when using
|
|
1632
1640
|
// the same reference again
|
|
1633
1641
|
while (parent &&
|
|
1634
|
-
parent._observableInstanceState === 0 /* UNINITIALIZED */) {
|
|
1642
|
+
parent._observableInstanceState === 0 /* ObservableInstanceLifecycle.UNINITIALIZED */) {
|
|
1635
1643
|
parentChain.unshift(parent);
|
|
1636
1644
|
parent = parent.parent;
|
|
1637
1645
|
}
|
|
@@ -1665,7 +1673,7 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
1665
1673
|
finally {
|
|
1666
1674
|
this._isRunningAction = false;
|
|
1667
1675
|
}
|
|
1668
|
-
this._observableInstanceState = 2 /* CREATED */;
|
|
1676
|
+
this._observableInstanceState = 2 /* ObservableInstanceLifecycle.CREATED */;
|
|
1669
1677
|
this._snapshotComputed.trackAndCompute();
|
|
1670
1678
|
if (this.isRoot)
|
|
1671
1679
|
this._addSnapshotReaction();
|
|
@@ -1748,10 +1756,10 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
1748
1756
|
throw fail("assertion failed: new parent expected");
|
|
1749
1757
|
}
|
|
1750
1758
|
if (this.parent && parentChanged) {
|
|
1751
|
-
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 ".concat(this, " to path '").concat(newParent.path, "/").concat(subpath, "'."));
|
|
1752
1760
|
}
|
|
1753
1761
|
if (!this.parent && newParent.root === this) {
|
|
1754
|
-
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 ".concat(this, " to path '").concat(newParent.path, "/").concat(subpath, "'"));
|
|
1755
1763
|
}
|
|
1756
1764
|
if (!this.parent && !!this.environment && this.environment !== newParent.root.environment) {
|
|
1757
1765
|
throw fail("A state tree cannot be made part of another state tree as long as their environments are different.");
|
|
@@ -1810,7 +1818,7 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
1810
1818
|
value: function () {
|
|
1811
1819
|
if (!this.isAlive)
|
|
1812
1820
|
return this._snapshotUponDeath;
|
|
1813
|
-
return this._observableInstanceState === 2 /* CREATED */
|
|
1821
|
+
return this._observableInstanceState === 2 /* ObservableInstanceLifecycle.CREATED */
|
|
1814
1822
|
? this._getActualSnapshot()
|
|
1815
1823
|
: this._getCachedInitialSnapshot();
|
|
1816
1824
|
}
|
|
@@ -1883,9 +1891,9 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
1883
1891
|
if (actionContext && actionContext.name != null) {
|
|
1884
1892
|
// try to use the context, and if it not available use the node one
|
|
1885
1893
|
var actionPath = (actionContext && actionContext.context && getPath(actionContext.context)) || escapedPath;
|
|
1886
|
-
actionFullPath = actionPath
|
|
1894
|
+
actionFullPath = "".concat(actionPath, ".").concat(actionContext.name, "()");
|
|
1887
1895
|
}
|
|
1888
|
-
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: '".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.");
|
|
1889
1897
|
}
|
|
1890
1898
|
});
|
|
1891
1899
|
Object.defineProperty(ObjectNode.prototype, "getChildNode", {
|
|
@@ -1898,7 +1906,7 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
1898
1906
|
});
|
|
1899
1907
|
this._autoUnbox = false;
|
|
1900
1908
|
try {
|
|
1901
|
-
return this._observableInstanceState === 2 /* CREATED */
|
|
1909
|
+
return this._observableInstanceState === 2 /* ObservableInstanceLifecycle.CREATED */
|
|
1902
1910
|
? this.type.getChildNode(this, subpath)
|
|
1903
1911
|
: this._childNodes[subpath];
|
|
1904
1912
|
}
|
|
@@ -1915,7 +1923,7 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
1915
1923
|
this.assertAlive(EMPTY_OBJECT);
|
|
1916
1924
|
this._autoUnbox = false;
|
|
1917
1925
|
try {
|
|
1918
|
-
return this._observableInstanceState === 2 /* CREATED */
|
|
1926
|
+
return this._observableInstanceState === 2 /* ObservableInstanceLifecycle.CREATED */
|
|
1919
1927
|
? this.type.getChildren(this)
|
|
1920
1928
|
: convertChildNodesToArray(this._childNodes);
|
|
1921
1929
|
}
|
|
@@ -1946,7 +1954,7 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
1946
1954
|
value: function (context) {
|
|
1947
1955
|
this.assertAlive(context);
|
|
1948
1956
|
if (!this.isRunningAction() && this.isProtected) {
|
|
1949
|
-
throw fail("Cannot modify '"
|
|
1957
|
+
throw fail("Cannot modify '".concat(this, "', the object is protected and can only be modified by using an action."));
|
|
1950
1958
|
}
|
|
1951
1959
|
}
|
|
1952
1960
|
});
|
|
@@ -1978,8 +1986,8 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
1978
1986
|
writable: true,
|
|
1979
1987
|
value: function () {
|
|
1980
1988
|
var path = (this.isAlive ? this.path : this.pathUponDeath) || "<root>";
|
|
1981
|
-
var identifier = this.identifier ? "(id: "
|
|
1982
|
-
return this.type.name
|
|
1989
|
+
var identifier = this.identifier ? "(id: ".concat(this.identifier, ")") : "";
|
|
1990
|
+
return "".concat(this.type.name, "@").concat(path).concat(identifier).concat(this.isAlive ? "" : " [dead]");
|
|
1983
1991
|
}
|
|
1984
1992
|
});
|
|
1985
1993
|
Object.defineProperty(ObjectNode.prototype, "finalizeCreation", {
|
|
@@ -2061,7 +2069,7 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
2061
2069
|
configurable: true,
|
|
2062
2070
|
writable: true,
|
|
2063
2071
|
value: function () {
|
|
2064
|
-
if (this._observableInstanceState === 0 /* UNINITIALIZED */) {
|
|
2072
|
+
if (this._observableInstanceState === 0 /* ObservableInstanceLifecycle.UNINITIALIZED */) {
|
|
2065
2073
|
return;
|
|
2066
2074
|
}
|
|
2067
2075
|
this.getChildren().forEach(function (node) {
|
|
@@ -2070,8 +2078,8 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
2070
2078
|
// beforeDestroy should run before the disposers since else we could end up in a situation where
|
|
2071
2079
|
// a disposer added with addDisposer at this stage (beforeDestroy) is actually never released
|
|
2072
2080
|
this.baseAboutToDie();
|
|
2073
|
-
this._internalEventsEmit("dispose" /* Dispose */);
|
|
2074
|
-
this._internalEventsClear("dispose" /* Dispose */);
|
|
2081
|
+
this._internalEventsEmit("dispose" /* InternalEvents.Dispose */);
|
|
2082
|
+
this._internalEventsClear("dispose" /* InternalEvents.Dispose */);
|
|
2075
2083
|
}
|
|
2076
2084
|
});
|
|
2077
2085
|
Object.defineProperty(ObjectNode.prototype, "finalizeDeath", {
|
|
@@ -2097,7 +2105,7 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
2097
2105
|
writable: true,
|
|
2098
2106
|
value: function (onChange) {
|
|
2099
2107
|
this._addSnapshotReaction();
|
|
2100
|
-
return this._internalEventsRegister("snapshot" /* Snapshot */, onChange);
|
|
2108
|
+
return this._internalEventsRegister("snapshot" /* InternalEvents.Snapshot */, onChange);
|
|
2101
2109
|
}
|
|
2102
2110
|
});
|
|
2103
2111
|
Object.defineProperty(ObjectNode.prototype, "emitSnapshot", {
|
|
@@ -2105,7 +2113,7 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
2105
2113
|
configurable: true,
|
|
2106
2114
|
writable: true,
|
|
2107
2115
|
value: function (snapshot) {
|
|
2108
|
-
this._internalEventsEmit("snapshot" /* Snapshot */, snapshot);
|
|
2116
|
+
this._internalEventsEmit("snapshot" /* InternalEvents.Snapshot */, snapshot);
|
|
2109
2117
|
}
|
|
2110
2118
|
});
|
|
2111
2119
|
Object.defineProperty(ObjectNode.prototype, "onPatch", {
|
|
@@ -2113,7 +2121,7 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
2113
2121
|
configurable: true,
|
|
2114
2122
|
writable: true,
|
|
2115
2123
|
value: function (handler) {
|
|
2116
|
-
return this._internalEventsRegister("patch" /* Patch */, handler);
|
|
2124
|
+
return this._internalEventsRegister("patch" /* InternalEvents.Patch */, handler);
|
|
2117
2125
|
}
|
|
2118
2126
|
});
|
|
2119
2127
|
Object.defineProperty(ObjectNode.prototype, "emitPatch", {
|
|
@@ -2121,12 +2129,12 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
2121
2129
|
configurable: true,
|
|
2122
2130
|
writable: true,
|
|
2123
2131
|
value: function (basePatch, source) {
|
|
2124
|
-
if (this._internalEventsHasSubscribers("patch" /* Patch */)) {
|
|
2132
|
+
if (this._internalEventsHasSubscribers("patch" /* InternalEvents.Patch */)) {
|
|
2125
2133
|
var localizedPatch = extend({}, basePatch, {
|
|
2126
2134
|
path: source.path.substr(this.path.length) + "/" + basePatch.path // calculate the relative path of the patch
|
|
2127
2135
|
});
|
|
2128
2136
|
var _a = __read(splitPatch(localizedPatch), 2), patch = _a[0], reversePatch = _a[1];
|
|
2129
|
-
this._internalEventsEmit("patch" /* Patch */, patch, reversePatch);
|
|
2137
|
+
this._internalEventsEmit("patch" /* InternalEvents.Patch */, patch, reversePatch);
|
|
2130
2138
|
}
|
|
2131
2139
|
if (this.parent)
|
|
2132
2140
|
this.parent.emitPatch(basePatch, source);
|
|
@@ -2137,7 +2145,7 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
2137
2145
|
configurable: true,
|
|
2138
2146
|
writable: true,
|
|
2139
2147
|
value: function (disposer) {
|
|
2140
|
-
return this._internalEventsHas("dispose" /* Dispose */, disposer);
|
|
2148
|
+
return this._internalEventsHas("dispose" /* InternalEvents.Dispose */, disposer);
|
|
2141
2149
|
}
|
|
2142
2150
|
});
|
|
2143
2151
|
Object.defineProperty(ObjectNode.prototype, "addDisposer", {
|
|
@@ -2146,7 +2154,7 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
2146
2154
|
writable: true,
|
|
2147
2155
|
value: function (disposer) {
|
|
2148
2156
|
if (!this.hasDisposer(disposer)) {
|
|
2149
|
-
this._internalEventsRegister("dispose" /* Dispose */, disposer, true);
|
|
2157
|
+
this._internalEventsRegister("dispose" /* InternalEvents.Dispose */, disposer, true);
|
|
2150
2158
|
return;
|
|
2151
2159
|
}
|
|
2152
2160
|
throw fail("cannot add a disposer when it is already registered for execution");
|
|
@@ -2157,10 +2165,10 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
2157
2165
|
configurable: true,
|
|
2158
2166
|
writable: true,
|
|
2159
2167
|
value: function (disposer) {
|
|
2160
|
-
if (!this._internalEventsHas("dispose" /* Dispose */, disposer)) {
|
|
2168
|
+
if (!this._internalEventsHas("dispose" /* InternalEvents.Dispose */, disposer)) {
|
|
2161
2169
|
throw fail("cannot remove a disposer which was never registered for execution");
|
|
2162
2170
|
}
|
|
2163
|
-
this._internalEventsUnregister("dispose" /* Dispose */, disposer);
|
|
2171
|
+
this._internalEventsUnregister("dispose" /* InternalEvents.Dispose */, disposer);
|
|
2164
2172
|
}
|
|
2165
2173
|
});
|
|
2166
2174
|
Object.defineProperty(ObjectNode.prototype, "removeMiddleware", {
|
|
@@ -2268,7 +2276,7 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
2268
2276
|
args[_i - 1] = arguments[_i];
|
|
2269
2277
|
}
|
|
2270
2278
|
if (this._internalEvents) {
|
|
2271
|
-
(_a = this._internalEvents).emit.apply(_a,
|
|
2279
|
+
(_a = this._internalEvents).emit.apply(_a, __spreadArray([event], __read(args), false));
|
|
2272
2280
|
}
|
|
2273
2281
|
}
|
|
2274
2282
|
});
|
|
@@ -2911,11 +2919,11 @@ function serializeArgument(node, actionName, index, arg) {
|
|
|
2911
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
|
|
2912
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
|
|
2913
2921
|
if (isStateTreeNode(arg))
|
|
2914
|
-
return serializeTheUnserializable("[MSTNode: "
|
|
2922
|
+
return serializeTheUnserializable("[MSTNode: ".concat(getType(arg).name, "]"));
|
|
2915
2923
|
if (typeof arg === "function")
|
|
2916
2924
|
return serializeTheUnserializable("[function]");
|
|
2917
2925
|
if (typeof arg === "object" && !isPlainObject(arg) && !isArray(arg))
|
|
2918
|
-
return serializeTheUnserializable("[object "
|
|
2926
|
+
return serializeTheUnserializable("[object ".concat((arg && arg.constructor && arg.constructor.name) || "Complex Object", "]"));
|
|
2919
2927
|
try {
|
|
2920
2928
|
// Check if serializable, cycle free etc...
|
|
2921
2929
|
// MWE: there must be a better way....
|
|
@@ -2956,7 +2964,7 @@ function applyAction(target, actions) {
|
|
|
2956
2964
|
function baseApplyAction(target, action) {
|
|
2957
2965
|
var resolvedTarget = tryResolve(target, action.path || "");
|
|
2958
2966
|
if (!resolvedTarget)
|
|
2959
|
-
throw fail("Invalid action path: "
|
|
2967
|
+
throw fail("Invalid action path: ".concat(action.path || ""));
|
|
2960
2968
|
var node = getStateTreeNode(resolvedTarget);
|
|
2961
2969
|
// Reserved functions
|
|
2962
2970
|
if (action.name === "@APPLY_PATCHES") {
|
|
@@ -2966,7 +2974,7 @@ function baseApplyAction(target, action) {
|
|
|
2966
2974
|
return applySnapshot.call(null, resolvedTarget, action.args[0]);
|
|
2967
2975
|
}
|
|
2968
2976
|
if (!(typeof resolvedTarget[action.name] === "function"))
|
|
2969
|
-
throw fail("Action '"
|
|
2977
|
+
throw fail("Action '".concat(action.name, "' does not exist in '").concat(node.path, "'"));
|
|
2970
2978
|
return resolvedTarget[action.name].apply(resolvedTarget, action.args ? action.args.map(function (v) { return deserializeArgument(node, v); }) : []);
|
|
2971
2979
|
}
|
|
2972
2980
|
/**
|
|
@@ -3171,7 +3179,7 @@ function createActionInvoker(target, name, fn) {
|
|
|
3171
3179
|
tree: getRoot(target),
|
|
3172
3180
|
rootId: parentContext ? parentContext.rootId : id,
|
|
3173
3181
|
parentId: parentContext ? parentContext.id : 0,
|
|
3174
|
-
allParentIds: parentContext ?
|
|
3182
|
+
allParentIds: parentContext ? __spreadArray(__spreadArray([], __read(parentContext.allParentIds), false), [parentContext.id], false) : [],
|
|
3175
3183
|
parentEvent: parentContext,
|
|
3176
3184
|
parentActionEvent: parentActionContext
|
|
3177
3185
|
}, fn);
|
|
@@ -3327,11 +3335,11 @@ function runMiddleWares(node, baseCall, originalFn) {
|
|
|
3327
3335
|
if (devMode()) {
|
|
3328
3336
|
if (!nextInvoked && !abortInvoked) {
|
|
3329
3337
|
var node2 = getStateTreeNode(call.tree);
|
|
3330
|
-
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 ".concat(handler.name, " for the action: \"").concat(call.name, "\" on the node: ").concat(node2.type.name, " was invoked."));
|
|
3331
3339
|
}
|
|
3332
3340
|
else if (nextInvoked && abortInvoked) {
|
|
3333
3341
|
var node2 = getStateTreeNode(call.tree);
|
|
3334
|
-
throw fail("The next() and abort() callback within the middleware "
|
|
3342
|
+
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."));
|
|
3335
3343
|
}
|
|
3336
3344
|
}
|
|
3337
3345
|
return result;
|
|
@@ -3381,7 +3389,7 @@ function safeStringify(value) {
|
|
|
3381
3389
|
}
|
|
3382
3390
|
catch (e) {
|
|
3383
3391
|
// istanbul ignore next
|
|
3384
|
-
return "<Unserializable: "
|
|
3392
|
+
return "<Unserializable: ".concat(e, ">");
|
|
3385
3393
|
}
|
|
3386
3394
|
}
|
|
3387
3395
|
/**
|
|
@@ -3390,15 +3398,15 @@ function safeStringify(value) {
|
|
|
3390
3398
|
*/
|
|
3391
3399
|
function prettyPrintValue(value) {
|
|
3392
3400
|
return typeof value === "function"
|
|
3393
|
-
? "<function"
|
|
3401
|
+
? "<function".concat(value.name ? " " + value.name : "", ">")
|
|
3394
3402
|
: isStateTreeNode(value)
|
|
3395
|
-
? "<"
|
|
3396
|
-
: "`"
|
|
3403
|
+
? "<".concat(value, ">")
|
|
3404
|
+
: "`".concat(safeStringify(value), "`");
|
|
3397
3405
|
}
|
|
3398
3406
|
function shortenPrintValue(valueInString) {
|
|
3399
3407
|
return valueInString.length < 280
|
|
3400
3408
|
? valueInString
|
|
3401
|
-
: valueInString.substring(0, 272)
|
|
3409
|
+
: "".concat(valueInString.substring(0, 272), "......").concat(valueInString.substring(valueInString.length - 8));
|
|
3402
3410
|
}
|
|
3403
3411
|
function toErrorString(error) {
|
|
3404
3412
|
var value = error.value;
|
|
@@ -3410,19 +3418,19 @@ function toErrorString(error) {
|
|
|
3410
3418
|
})
|
|
3411
3419
|
.filter(function (path) { return path.length > 0; })
|
|
3412
3420
|
.join("/");
|
|
3413
|
-
var pathPrefix = fullPath.length > 0 ? "at path \"/"
|
|
3421
|
+
var pathPrefix = fullPath.length > 0 ? "at path \"/".concat(fullPath, "\" ") : "";
|
|
3414
3422
|
var currentTypename = isStateTreeNode(value)
|
|
3415
|
-
? "value of type "
|
|
3423
|
+
? "value of type ".concat(getStateTreeNode(value).type.name, ":")
|
|
3416
3424
|
: isPrimitive(value)
|
|
3417
3425
|
? "value"
|
|
3418
3426
|
: "snapshot";
|
|
3419
3427
|
var isSnapshotCompatible = type && isStateTreeNode(value) && type.is(getStateTreeNode(value).snapshot);
|
|
3420
|
-
return (""
|
|
3421
|
-
(error.message ? " ("
|
|
3428
|
+
return ("".concat(pathPrefix).concat(currentTypename, " ").concat(prettyPrintValue(value), " is not assignable ").concat(type ? "to type: `".concat(type.name, "`") : "") +
|
|
3429
|
+
(error.message ? " (".concat(error.message, ")") : "") +
|
|
3422
3430
|
(type
|
|
3423
3431
|
? isPrimitiveType(type) || isPrimitive(value)
|
|
3424
3432
|
? "."
|
|
3425
|
-
: ", expected an instance of `"
|
|
3433
|
+
: ", expected an instance of `".concat(type.name, "` or a snapshot like `").concat(type.describe(), "` instead.") +
|
|
3426
3434
|
(isSnapshotCompatible
|
|
3427
3435
|
? " (Note that a snapshot of the provided value is compatible with the targeted type)"
|
|
3428
3436
|
: "")
|
|
@@ -3485,7 +3493,7 @@ function validationErrorsToString(type, value, errors) {
|
|
|
3485
3493
|
if (errors.length === 0) {
|
|
3486
3494
|
return undefined;
|
|
3487
3495
|
}
|
|
3488
|
-
return ("Error while converting "
|
|
3496
|
+
return ("Error while converting ".concat(shortenPrintValue(prettyPrintValue(value)), " to `").concat(type.name, "`:\n\n ") + errors.map(toErrorString).join("\n "));
|
|
3489
3497
|
}
|
|
3490
3498
|
|
|
3491
3499
|
var identifierCacheId = 0;
|
|
@@ -3533,7 +3541,7 @@ var IdentifierCache = /** @class */ (function () {
|
|
|
3533
3541
|
writable: true,
|
|
3534
3542
|
value: function (identifier) {
|
|
3535
3543
|
var modificationId = this.lastCacheModificationPerId.get(identifier) || 0;
|
|
3536
|
-
return this.cacheId
|
|
3544
|
+
return "".concat(this.cacheId, "-").concat(modificationId);
|
|
3537
3545
|
}
|
|
3538
3546
|
});
|
|
3539
3547
|
Object.defineProperty(IdentifierCache.prototype, "addNodeToCache", {
|
|
@@ -3648,9 +3656,9 @@ var IdentifierCache = /** @class */ (function () {
|
|
|
3648
3656
|
case 1:
|
|
3649
3657
|
return matches[0];
|
|
3650
3658
|
default:
|
|
3651
|
-
throw fail("Cannot resolve a reference to type '"
|
|
3659
|
+
throw fail("Cannot resolve a reference to type '".concat(type.name, "' with id: '").concat(identifier, "' unambigously, there are multiple candidates: ").concat(matches
|
|
3652
3660
|
.map(function (n) { return n.path; })
|
|
3653
|
-
.join(", "));
|
|
3661
|
+
.join(", ")));
|
|
3654
3662
|
}
|
|
3655
3663
|
}
|
|
3656
3664
|
});
|
|
@@ -3666,7 +3674,7 @@ function createObjectNode(type, parent, subpath, environment, initialValue) {
|
|
|
3666
3674
|
if (existingNode) {
|
|
3667
3675
|
if (existingNode.parent) {
|
|
3668
3676
|
// istanbul ignore next
|
|
3669
|
-
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 '".concat(parent ? parent.path : "", "/").concat(subpath, "', but it lives already at '").concat(existingNode.path, "'"));
|
|
3670
3678
|
}
|
|
3671
3679
|
if (parent) {
|
|
3672
3680
|
existingNode.setParent(parent, subpath);
|
|
@@ -3729,7 +3737,7 @@ function assertIsStateTreeNode(value, argNumber) {
|
|
|
3729
3737
|
function getStateTreeNode(value) {
|
|
3730
3738
|
if (!isStateTreeNode(value)) {
|
|
3731
3739
|
// istanbul ignore next
|
|
3732
|
-
throw fail("Value "
|
|
3740
|
+
throw fail("Value ".concat(value, " is no MST Node"));
|
|
3733
3741
|
}
|
|
3734
3742
|
return value.$treenode;
|
|
3735
3743
|
}
|
|
@@ -3755,7 +3763,7 @@ var doubleDot = function (_) { return ".."; };
|
|
|
3755
3763
|
function getRelativePathBetweenNodes(base, target) {
|
|
3756
3764
|
// PRE condition target is (a child of) base!
|
|
3757
3765
|
if (base.root !== target.root) {
|
|
3758
|
-
throw fail("Cannot calculate relative path: objects '"
|
|
3766
|
+
throw fail("Cannot calculate relative path: objects '".concat(base, "' and '").concat(target, "' are not part of the same object tree"));
|
|
3759
3767
|
}
|
|
3760
3768
|
var baseParts = splitJsonPath(base.path);
|
|
3761
3769
|
var targetParts = splitJsonPath(target.path);
|
|
@@ -3812,7 +3820,7 @@ function resolveNodeByPathParts(base, pathParts, failIfResolveFails) {
|
|
|
3812
3820
|
}
|
|
3813
3821
|
}
|
|
3814
3822
|
}
|
|
3815
|
-
throw fail("Could not resolve '"
|
|
3823
|
+
throw fail("Could not resolve '".concat(part, "' in path '").concat(joinJsonPath(pathParts.slice(0, i)) || "/", "' while resolving '").concat(joinJsonPath(pathParts), "'"));
|
|
3816
3824
|
}
|
|
3817
3825
|
}
|
|
3818
3826
|
catch (e) {
|
|
@@ -4132,7 +4140,7 @@ var EventHandler = /** @class */ (function () {
|
|
|
4132
4140
|
}
|
|
4133
4141
|
// make a copy just in case it changes
|
|
4134
4142
|
var handlers = this.handlers.slice();
|
|
4135
|
-
handlers.forEach(function (f) { return f.apply(void 0,
|
|
4143
|
+
handlers.forEach(function (f) { return f.apply(void 0, __spreadArray([], __read(args), false)); });
|
|
4136
4144
|
}
|
|
4137
4145
|
});
|
|
4138
4146
|
return EventHandler;
|
|
@@ -4225,7 +4233,7 @@ var EventHandlers = /** @class */ (function () {
|
|
|
4225
4233
|
}
|
|
4226
4234
|
var handler = this.eventHandlers && this.eventHandlers[event];
|
|
4227
4235
|
if (handler) {
|
|
4228
|
-
(_a = handler).emit.apply(_a,
|
|
4236
|
+
(_a = handler).emit.apply(_a, __spreadArray([], __read(args), false));
|
|
4229
4237
|
}
|
|
4230
4238
|
}
|
|
4231
4239
|
});
|
|
@@ -4270,7 +4278,7 @@ deprecated.ids = {};
|
|
|
4270
4278
|
* @hidden
|
|
4271
4279
|
*/
|
|
4272
4280
|
function warnError(msg) {
|
|
4273
|
-
console.warn(new Error("[mobx-state-tree] "
|
|
4281
|
+
console.warn(new Error("[mobx-state-tree] ".concat(msg)));
|
|
4274
4282
|
}
|
|
4275
4283
|
/**
|
|
4276
4284
|
* @internal
|
|
@@ -4295,7 +4303,7 @@ function assertArg(value, fn, typeName, argNumber) {
|
|
|
4295
4303
|
if (devMode()) {
|
|
4296
4304
|
if (!fn(value)) {
|
|
4297
4305
|
// istanbul ignore next
|
|
4298
|
-
throw fail("expected "
|
|
4306
|
+
throw fail("expected ".concat(typeName, " as argument ").concat(asArray(argNumber).join(" or "), ", got ").concat(value, " instead"));
|
|
4299
4307
|
}
|
|
4300
4308
|
}
|
|
4301
4309
|
}
|
|
@@ -4313,10 +4321,10 @@ function assertIsFunction(value, argNumber) {
|
|
|
4313
4321
|
function assertIsNumber(value, argNumber, min, max) {
|
|
4314
4322
|
assertArg(value, function (n) { return typeof n === "number"; }, "number", argNumber);
|
|
4315
4323
|
if (min !== undefined) {
|
|
4316
|
-
assertArg(value, function (n) { return n >= min; }, "number greater than "
|
|
4324
|
+
assertArg(value, function (n) { return n >= min; }, "number greater than ".concat(min), argNumber);
|
|
4317
4325
|
}
|
|
4318
4326
|
if (max !== undefined) {
|
|
4319
|
-
assertArg(value, function (n) { return n <= max; }, "number lesser than "
|
|
4327
|
+
assertArg(value, function (n) { return n <= max; }, "number lesser than ".concat(max), argNumber);
|
|
4320
4328
|
}
|
|
4321
4329
|
}
|
|
4322
4330
|
/**
|
|
@@ -4395,7 +4403,7 @@ function toGeneratorFunction(p) {
|
|
|
4395
4403
|
}
|
|
4396
4404
|
return __generator(this, function (_a) {
|
|
4397
4405
|
switch (_a.label) {
|
|
4398
|
-
case 0: return [4 /*yield*/, p.apply(void 0,
|
|
4406
|
+
case 0: return [4 /*yield*/, p.apply(void 0, __spreadArray([], __read(args), false))];
|
|
4399
4407
|
case 1: return [2 /*return*/, (_a.sent())];
|
|
4400
4408
|
}
|
|
4401
4409
|
});
|
|
@@ -4452,7 +4460,7 @@ function createFlowSpawner(name, generator) {
|
|
|
4452
4460
|
tree: parentContext.tree,
|
|
4453
4461
|
context: parentContext.context,
|
|
4454
4462
|
parentId: parentContext.id,
|
|
4455
|
-
allParentIds:
|
|
4463
|
+
allParentIds: __spreadArray(__spreadArray([], __read(parentContext.allParentIds), false), [parentContext.id], false),
|
|
4456
4464
|
rootId: parentContext.rootId,
|
|
4457
4465
|
parentEvent: parentContext,
|
|
4458
4466
|
parentActionEvent: parentActionContext
|
|
@@ -4632,7 +4640,7 @@ function splitJsonPath(path) {
|
|
|
4632
4640
|
stringStartsWith(path, "./") ||
|
|
4633
4641
|
stringStartsWith(path, "../");
|
|
4634
4642
|
if (!valid) {
|
|
4635
|
-
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 '".concat(path, "'"));
|
|
4636
4644
|
}
|
|
4637
4645
|
// '/a/b/c' -> ["a", "b", "c"]
|
|
4638
4646
|
// '../../b/c' -> ["..", "..", "b", "c"]
|
|
@@ -4678,7 +4686,7 @@ var SnapshotProcessor = /** @class */ (function (_super) {
|
|
|
4678
4686
|
configurable: true,
|
|
4679
4687
|
writable: true,
|
|
4680
4688
|
value: function () {
|
|
4681
|
-
return "snapshotProcessor("
|
|
4689
|
+
return "snapshotProcessor(".concat(this._subtype.describe(), ")");
|
|
4682
4690
|
}
|
|
4683
4691
|
});
|
|
4684
4692
|
Object.defineProperty(SnapshotProcessor.prototype, "preProcessSnapshot", {
|
|
@@ -5094,7 +5102,7 @@ var MapType = /** @class */ (function (_super) {
|
|
|
5094
5102
|
if (!type.identifierAttribute)
|
|
5095
5103
|
return current;
|
|
5096
5104
|
if (current && current !== type.identifierAttribute) {
|
|
5097
|
-
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 '".concat(current, "', but child of type '").concat(type.name, "' declared attribute '").concat(type.identifierAttribute, "' as identifier"));
|
|
5098
5106
|
}
|
|
5099
5107
|
return type.identifierAttribute;
|
|
5100
5108
|
}, undefined);
|
|
@@ -5218,7 +5226,7 @@ var MapType = /** @class */ (function (_super) {
|
|
|
5218
5226
|
if (this.identifierMode === MapIdentifierMode.YES && node instanceof ObjectNode) {
|
|
5219
5227
|
var identifier = node.identifier;
|
|
5220
5228
|
if (identifier !== expected)
|
|
5221
|
-
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 '".concat(identifier, "', but expected: '").concat(expected, "'"));
|
|
5222
5230
|
}
|
|
5223
5231
|
}
|
|
5224
5232
|
});
|
|
@@ -5390,7 +5398,7 @@ MapType.prototype.applySnapshot = action(MapType.prototype.applySnapshot);
|
|
|
5390
5398
|
* @returns
|
|
5391
5399
|
*/
|
|
5392
5400
|
function map(subtype) {
|
|
5393
|
-
return new MapType("Map<string, "
|
|
5401
|
+
return new MapType("Map<string, ".concat(subtype.name, ">"), subtype);
|
|
5394
5402
|
}
|
|
5395
5403
|
/**
|
|
5396
5404
|
* Returns if a given value represents a map type.
|
|
@@ -5707,7 +5715,7 @@ ArrayType.prototype.applySnapshot = action(ArrayType.prototype.applySnapshot);
|
|
|
5707
5715
|
*/
|
|
5708
5716
|
function array(subtype) {
|
|
5709
5717
|
assertIsType(subtype, 1);
|
|
5710
|
-
return new ArrayType(subtype.name
|
|
5718
|
+
return new ArrayType("".concat(subtype.name, "[]"), subtype);
|
|
5711
5719
|
}
|
|
5712
5720
|
function reconcileArrayChildren(parent, childType, oldNodes, newValues, newPaths) {
|
|
5713
5721
|
var nothingChanged = true;
|
|
@@ -5741,7 +5749,7 @@ function reconcileArrayChildren(parent, childType, oldNodes, newValues, newPaths
|
|
|
5741
5749
|
// check if already belongs to the same parent. if so, avoid pushing item in. only swapping can occur.
|
|
5742
5750
|
if (isStateTreeNode(newValue) && getStateTreeNode(newValue).parent === parent) {
|
|
5743
5751
|
// this node is owned by this parent, but not in the reconcilable set, so it must be double
|
|
5744
|
-
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 '".concat(parent.path, "/").concat(newPath, "', but it lives already at '").concat(getStateTreeNode(newValue).path, "'"));
|
|
5745
5753
|
}
|
|
5746
5754
|
nothingChanged = false;
|
|
5747
5755
|
var newNode = valueAsNode(childType, parent, newPath, newValue);
|
|
@@ -5857,7 +5865,7 @@ function toPropertiesObject(declaredProps) {
|
|
|
5857
5865
|
var alreadySeenKeys = new Set();
|
|
5858
5866
|
keysList.forEach(function (key) {
|
|
5859
5867
|
if (alreadySeenKeys.has(key)) {
|
|
5860
|
-
throw fail(key
|
|
5868
|
+
throw fail("".concat(key, " is declared twice in the model. Model should not contain the same keys"));
|
|
5861
5869
|
}
|
|
5862
5870
|
alreadySeenKeys.add(key);
|
|
5863
5871
|
});
|
|
@@ -5865,7 +5873,7 @@ function toPropertiesObject(declaredProps) {
|
|
|
5865
5873
|
return keysList.reduce(function (props, key) {
|
|
5866
5874
|
// warn if user intended a HOOK
|
|
5867
5875
|
if (key in Hook) {
|
|
5868
|
-
throw fail("Hook '"
|
|
5876
|
+
throw fail("Hook '".concat(key, "' was defined as property. Hooks should be defined as part of the actions"));
|
|
5869
5877
|
}
|
|
5870
5878
|
// the user intended to use a view
|
|
5871
5879
|
var descriptor = Object.getOwnPropertyDescriptor(declaredProps, key);
|
|
@@ -5892,14 +5900,14 @@ function toPropertiesObject(declaredProps) {
|
|
|
5892
5900
|
else if (isType(value)) ;
|
|
5893
5901
|
// its a function, maybe the user wanted a view?
|
|
5894
5902
|
else if (devMode() && typeof value === "function") {
|
|
5895
|
-
throw fail("Invalid type definition for property '"
|
|
5903
|
+
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?"));
|
|
5896
5904
|
}
|
|
5897
5905
|
// no other complex values
|
|
5898
5906
|
else if (devMode() && typeof value === "object") {
|
|
5899
|
-
throw fail("Invalid type definition for property '"
|
|
5907
|
+
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."));
|
|
5900
5908
|
}
|
|
5901
5909
|
else {
|
|
5902
|
-
throw fail("Invalid type definition for property '"
|
|
5910
|
+
throw fail("Invalid type definition for property '".concat(key, "', cannot infer a type from a value like '").concat(value, "' (").concat(typeof value, ")"));
|
|
5903
5911
|
}
|
|
5904
5912
|
return props;
|
|
5905
5913
|
}, declaredProps);
|
|
@@ -6012,7 +6020,7 @@ var ModelType = /** @class */ (function (_super) {
|
|
|
6012
6020
|
this.forAllProps(function (propName, propType) {
|
|
6013
6021
|
if (propType.flags & TypeFlags.Identifier) {
|
|
6014
6022
|
if (identifierAttribute)
|
|
6015
|
-
throw fail("Cannot define property '"
|
|
6023
|
+
throw fail("Cannot define property '".concat(propName, "' as object identifier, property '").concat(identifierAttribute, "' is already defined as identifier property"));
|
|
6016
6024
|
identifierAttribute = propName;
|
|
6017
6025
|
}
|
|
6018
6026
|
});
|
|
@@ -6058,10 +6066,10 @@ var ModelType = /** @class */ (function (_super) {
|
|
|
6058
6066
|
Object.keys(actions).forEach(function (name) {
|
|
6059
6067
|
// warn if preprocessor was given
|
|
6060
6068
|
if (name === PRE_PROCESS_SNAPSHOT)
|
|
6061
|
-
throw fail("Cannot define action '"
|
|
6069
|
+
throw fail("Cannot define action '".concat(PRE_PROCESS_SNAPSHOT, "', it should be defined using 'type.preProcessSnapshot(fn)' instead"));
|
|
6062
6070
|
// warn if postprocessor was given
|
|
6063
6071
|
if (name === POST_PROCESS_SNAPSHOT)
|
|
6064
|
-
throw fail("Cannot define action '"
|
|
6072
|
+
throw fail("Cannot define action '".concat(POST_PROCESS_SNAPSHOT, "', it should be defined using 'type.postProcessSnapshot(fn)' instead"));
|
|
6065
6073
|
var action2 = actions[name];
|
|
6066
6074
|
// apply hook composition
|
|
6067
6075
|
var baseAction = self[name];
|
|
@@ -6091,7 +6099,7 @@ var ModelType = /** @class */ (function (_super) {
|
|
|
6091
6099
|
value: function (fn) {
|
|
6092
6100
|
var _this = this;
|
|
6093
6101
|
if (typeof fn !== "function") {
|
|
6094
|
-
throw fail("You passed an "
|
|
6102
|
+
throw fail("You passed an ".concat(typeof fn, " to volatile state as an argument, when function is expected"));
|
|
6095
6103
|
}
|
|
6096
6104
|
var stateInitializer = function (self) {
|
|
6097
6105
|
_this.instantiateVolatileState(self, fn(self));
|
|
@@ -6120,7 +6128,7 @@ var ModelType = /** @class */ (function (_super) {
|
|
|
6120
6128
|
var initializer = function (self) {
|
|
6121
6129
|
var _a = fn(self), actions = _a.actions, views = _a.views, state = _a.state, rest = __rest(_a, ["actions", "views", "state"]);
|
|
6122
6130
|
for (var key in rest)
|
|
6123
|
-
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 '".concat(key, "'"));
|
|
6124
6132
|
if (state)
|
|
6125
6133
|
_this.instantiateVolatileState(self, state);
|
|
6126
6134
|
if (views)
|
|
@@ -6304,7 +6312,7 @@ var ModelType = /** @class */ (function (_super) {
|
|
|
6304
6312
|
atom.reportObserved();
|
|
6305
6313
|
}
|
|
6306
6314
|
catch (e) {
|
|
6307
|
-
throw fail(name
|
|
6315
|
+
throw fail("".concat(name, " property is declared twice"));
|
|
6308
6316
|
}
|
|
6309
6317
|
res[name] = _this.getChildNode(node, name).snapshot;
|
|
6310
6318
|
});
|
|
@@ -6332,7 +6340,7 @@ var ModelType = /** @class */ (function (_super) {
|
|
|
6332
6340
|
writable: true,
|
|
6333
6341
|
value: function (node, subpath, patch) {
|
|
6334
6342
|
if (!(patch.op === "replace" || patch.op === "add")) {
|
|
6335
|
-
throw fail("object does not support operation "
|
|
6343
|
+
throw fail("object does not support operation ".concat(patch.op));
|
|
6336
6344
|
}
|
|
6337
6345
|
node.storedValue[subpath] = patch.value;
|
|
6338
6346
|
}
|
|
@@ -6564,7 +6572,7 @@ var CoreType = /** @class */ (function (_super) {
|
|
|
6564
6572
|
return typeCheckSuccess();
|
|
6565
6573
|
}
|
|
6566
6574
|
var typeName = this.name === "Date" ? "Date or a unix milliseconds timestamp" : this.name;
|
|
6567
|
-
return typeCheckFailure(context, value, "Value is not a "
|
|
6575
|
+
return typeCheckFailure(context, value, "Value is not a ".concat(typeName));
|
|
6568
6576
|
}
|
|
6569
6577
|
});
|
|
6570
6578
|
return CoreType;
|
|
@@ -6757,7 +6765,7 @@ var Literal = /** @class */ (function (_super) {
|
|
|
6757
6765
|
if (isPrimitive(value) && value === this.value) {
|
|
6758
6766
|
return typeCheckSuccess();
|
|
6759
6767
|
}
|
|
6760
|
-
return typeCheckFailure(context, value, "Value is not a literal "
|
|
6768
|
+
return typeCheckFailure(context, value, "Value is not a literal ".concat(JSON.stringify(this.value)));
|
|
6761
6769
|
}
|
|
6762
6770
|
});
|
|
6763
6771
|
return Literal;
|
|
@@ -6939,7 +6947,7 @@ function enumeration(name, options) {
|
|
|
6939
6947
|
assertIsString(option, i + 1);
|
|
6940
6948
|
});
|
|
6941
6949
|
}
|
|
6942
|
-
var type = union.apply(void 0,
|
|
6950
|
+
var type = union.apply(void 0, __spreadArray([], __read(realOptions.map(function (option) { return literal("" + option); })), false));
|
|
6943
6951
|
if (typeof name === "string")
|
|
6944
6952
|
type.name = name;
|
|
6945
6953
|
return type;
|
|
@@ -7035,7 +7043,7 @@ var Union = /** @class */ (function (_super) {
|
|
|
7035
7043
|
if (this._dispatcher) {
|
|
7036
7044
|
return this._dispatcher(value);
|
|
7037
7045
|
}
|
|
7038
|
-
// find the most
|
|
7046
|
+
// find the most accommodating type
|
|
7039
7047
|
// if we are using reconciliation try the current node type first (fix for #1045)
|
|
7040
7048
|
if (reconcileCurrentType) {
|
|
7041
7049
|
if (reconcileCurrentType.is(value)) {
|
|
@@ -7099,7 +7107,7 @@ function union(optionsOrType) {
|
|
|
7099
7107
|
otherTypes[_i - 1] = arguments[_i];
|
|
7100
7108
|
}
|
|
7101
7109
|
var options = isType(optionsOrType) ? undefined : optionsOrType;
|
|
7102
|
-
var types = isType(optionsOrType) ?
|
|
7110
|
+
var types = isType(optionsOrType) ? __spreadArray([optionsOrType], __read(otherTypes), false) : otherTypes;
|
|
7103
7111
|
var name = "(" + types.map(function (type) { return type.name; }).join(" | ") + ")";
|
|
7104
7112
|
// check all options
|
|
7105
7113
|
if (devMode()) {
|
|
@@ -7461,7 +7469,7 @@ var Late = /** @class */ (function (_super) {
|
|
|
7461
7469
|
* @returns
|
|
7462
7470
|
*/
|
|
7463
7471
|
function late(nameOrType, maybeType) {
|
|
7464
|
-
var name = typeof nameOrType === "string" ? nameOrType : "late("
|
|
7472
|
+
var name = typeof nameOrType === "string" ? nameOrType : "late(".concat(nameOrType.toString(), ")");
|
|
7465
7473
|
var type = typeof nameOrType === "string" ? maybeType : nameOrType;
|
|
7466
7474
|
// checks that the type is actually a late type
|
|
7467
7475
|
if (devMode()) {
|
|
@@ -7533,7 +7541,7 @@ var Lazy = /** @class */ (function (_super) {
|
|
|
7533
7541
|
node.parent.applyPatches([
|
|
7534
7542
|
{
|
|
7535
7543
|
op: "replace",
|
|
7536
|
-
path: "/"
|
|
7544
|
+
path: "/".concat(node.subpath),
|
|
7537
7545
|
value: node.snapshot
|
|
7538
7546
|
}
|
|
7539
7547
|
]);
|
|
@@ -7547,7 +7555,7 @@ var Lazy = /** @class */ (function (_super) {
|
|
|
7547
7555
|
configurable: true,
|
|
7548
7556
|
writable: true,
|
|
7549
7557
|
value: function () {
|
|
7550
|
-
return "<lazy "
|
|
7558
|
+
return "<lazy ".concat(this.name, ">");
|
|
7551
7559
|
}
|
|
7552
7560
|
});
|
|
7553
7561
|
Object.defineProperty(Lazy.prototype, "instantiate", {
|
|
@@ -7601,7 +7609,7 @@ var Lazy = /** @class */ (function (_super) {
|
|
|
7601
7609
|
var Frozen = /** @class */ (function (_super) {
|
|
7602
7610
|
__extends(Frozen, _super);
|
|
7603
7611
|
function Frozen(subType) {
|
|
7604
|
-
var _this = _super.call(this, subType ? "frozen("
|
|
7612
|
+
var _this = _super.call(this, subType ? "frozen(".concat(subType.name, ")") : "frozen") || this;
|
|
7605
7613
|
Object.defineProperty(_this, "subType", {
|
|
7606
7614
|
enumerable: true,
|
|
7607
7615
|
configurable: true,
|
|
@@ -7757,7 +7765,7 @@ var StoredReference = /** @class */ (function () {
|
|
|
7757
7765
|
this.identifier = id;
|
|
7758
7766
|
}
|
|
7759
7767
|
else {
|
|
7760
|
-
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: '".concat(value, "'"));
|
|
7761
7769
|
}
|
|
7762
7770
|
}
|
|
7763
7771
|
Object.defineProperty(StoredReference.prototype, "updateResolvedReference", {
|
|
@@ -7774,7 +7782,7 @@ var StoredReference = /** @class */ (function () {
|
|
|
7774
7782
|
// reference was initialized with the identifier of the target
|
|
7775
7783
|
var target = root.identifierCache.resolve(targetType, normalizedId);
|
|
7776
7784
|
if (!target) {
|
|
7777
|
-
throw new InvalidReferenceError("[mobx-state-tree] Failed to resolve reference '"
|
|
7785
|
+
throw new InvalidReferenceError("[mobx-state-tree] Failed to resolve reference '".concat(this.identifier, "' to type '").concat(this.targetType.name, "' (from node: ").concat(node.path, ")"));
|
|
7778
7786
|
}
|
|
7779
7787
|
this.resolvedReference = {
|
|
7780
7788
|
node: target,
|
|
@@ -7813,7 +7821,7 @@ var InvalidReferenceError = /** @class */ (function (_super) {
|
|
|
7813
7821
|
var BaseReferenceType = /** @class */ (function (_super) {
|
|
7814
7822
|
__extends(BaseReferenceType, _super);
|
|
7815
7823
|
function BaseReferenceType(targetType, onInvalidated) {
|
|
7816
|
-
var _this = _super.call(this, "reference("
|
|
7824
|
+
var _this = _super.call(this, "reference(".concat(targetType.name, ")")) || this;
|
|
7817
7825
|
Object.defineProperty(_this, "targetType", {
|
|
7818
7826
|
enumerable: true,
|
|
7819
7827
|
configurable: true,
|
|
@@ -8238,7 +8246,7 @@ var BaseIdentifierType = /** @class */ (function (_super) {
|
|
|
8238
8246
|
value: function (current, newValue, parent, subpath) {
|
|
8239
8247
|
// we don't consider detaching here since identifier are scalar nodes, and scalar nodes cannot be detached
|
|
8240
8248
|
if (current.storedValue !== newValue)
|
|
8241
|
-
throw fail("Tried to change identifier from '"
|
|
8249
|
+
throw fail("Tried to change identifier from '".concat(current.storedValue, "' to '").concat(newValue, "'. Changing identifiers is not allowed."));
|
|
8242
8250
|
current.setParent(parent, subpath);
|
|
8243
8251
|
return current;
|
|
8244
8252
|
}
|
|
@@ -8249,7 +8257,7 @@ var BaseIdentifierType = /** @class */ (function (_super) {
|
|
|
8249
8257
|
writable: true,
|
|
8250
8258
|
value: function (value, context) {
|
|
8251
8259
|
if (typeof value !== this.validType) {
|
|
8252
|
-
return typeCheckFailure(context, value, "Value is not a valid "
|
|
8260
|
+
return typeCheckFailure(context, value, "Value is not a valid ".concat(this.describe(), ", expected a ").concat(this.validType));
|
|
8253
8261
|
}
|
|
8254
8262
|
return typeCheckSuccess();
|
|
8255
8263
|
}
|
|
@@ -8460,7 +8468,7 @@ var CustomType = /** @class */ (function (_super) {
|
|
|
8460
8468
|
return typeCheckSuccess();
|
|
8461
8469
|
var typeError = this.options.getValidationMessage(value);
|
|
8462
8470
|
if (typeError) {
|
|
8463
|
-
return typeCheckFailure(context, value, "Invalid value for type '"
|
|
8471
|
+
return typeCheckFailure(context, value, "Invalid value for type '".concat(this.name, "': ").concat(typeError));
|
|
8464
8472
|
}
|
|
8465
8473
|
return typeCheckSuccess();
|
|
8466
8474
|
}
|