mobx-state-tree 5.4.0 → 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 +172 -164
- package/dist/mobx-state-tree.min.js +1 -16
- package/dist/mobx-state-tree.module.js +172 -164
- package/dist/mobx-state-tree.umd.js +174 -166
- 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
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('mobx')) :
|
|
3
3
|
typeof define === 'function' && define.amd ? define(['exports', 'mobx'], factory) :
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.mobxStateTree = {}, global.mobx));
|
|
5
|
-
}(this, (function (exports, mobx) { 'use strict';
|
|
5
|
+
})(this, (function (exports, mobx) { 'use strict';
|
|
6
6
|
|
|
7
7
|
var livelinessChecking = "warn";
|
|
8
8
|
/**
|
|
@@ -49,7 +49,7 @@
|
|
|
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 @@
|
|
|
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 @@
|
|
|
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 @@
|
|
|
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)
|
|
@@ -348,7 +356,7 @@
|
|
|
348
356
|
assertIsStateTreeNode(target, 1);
|
|
349
357
|
var node = getStateTreeNode(target);
|
|
350
358
|
if (!node.isRoot)
|
|
351
|
-
throw fail
|
|
359
|
+
throw fail("`protect` can only be invoked on root nodes");
|
|
352
360
|
node.isProtectionEnabled = true;
|
|
353
361
|
}
|
|
354
362
|
/**
|
|
@@ -380,7 +388,7 @@
|
|
|
380
388
|
assertIsStateTreeNode(target, 1);
|
|
381
389
|
var node = getStateTreeNode(target);
|
|
382
390
|
if (!node.isRoot)
|
|
383
|
-
throw fail
|
|
391
|
+
throw fail("`unprotect` can only be invoked on root nodes");
|
|
384
392
|
node.isProtectionEnabled = false;
|
|
385
393
|
}
|
|
386
394
|
/**
|
|
@@ -463,7 +471,7 @@
|
|
|
463
471
|
return parent.storedValue;
|
|
464
472
|
parent = parent.parent;
|
|
465
473
|
}
|
|
466
|
-
throw fail
|
|
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 @@
|
|
|
501
509
|
return parent.storedValue;
|
|
502
510
|
parent = parent.parent;
|
|
503
511
|
}
|
|
504
|
-
throw fail
|
|
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.
|
|
@@ -618,7 +626,7 @@
|
|
|
618
626
|
}
|
|
619
627
|
}
|
|
620
628
|
else {
|
|
621
|
-
throw fail
|
|
629
|
+
throw fail("The reference to be checked is not one of node, null or undefined");
|
|
622
630
|
}
|
|
623
631
|
}
|
|
624
632
|
catch (e) {
|
|
@@ -646,7 +654,7 @@
|
|
|
646
654
|
return checkIfAlive ? isAlive(node) : true;
|
|
647
655
|
}
|
|
648
656
|
else {
|
|
649
|
-
throw fail
|
|
657
|
+
throw fail("The reference to be checked is not one of node, null or undefined");
|
|
650
658
|
}
|
|
651
659
|
}
|
|
652
660
|
catch (e) {
|
|
@@ -1301,7 +1309,7 @@
|
|
|
1301
1309
|
get: function () {
|
|
1302
1310
|
// future optimization: store root ref in the node and maintain it
|
|
1303
1311
|
if (!this.parent)
|
|
1304
|
-
throw fail
|
|
1312
|
+
throw fail("This scalar node is not part of a tree");
|
|
1305
1313
|
return this.parent.root;
|
|
1306
1314
|
},
|
|
1307
1315
|
enumerable: false,
|
|
@@ -1320,15 +1328,15 @@
|
|
|
1320
1328
|
{
|
|
1321
1329
|
if (!subpath) {
|
|
1322
1330
|
// istanbul ignore next
|
|
1323
|
-
throw fail
|
|
1331
|
+
throw fail("assertion failed: subpath expected");
|
|
1324
1332
|
}
|
|
1325
1333
|
if (!newParent) {
|
|
1326
1334
|
// istanbul ignore next
|
|
1327
|
-
throw fail
|
|
1335
|
+
throw fail("assertion failed: parent expected");
|
|
1328
1336
|
}
|
|
1329
1337
|
if (parentChanged) {
|
|
1330
1338
|
// istanbul ignore next
|
|
1331
|
-
throw fail
|
|
1339
|
+
throw fail("assertion failed: scalar nodes cannot change their parent");
|
|
1332
1340
|
}
|
|
1333
1341
|
}
|
|
1334
1342
|
this.environment = undefined; // use parent's
|
|
@@ -1356,7 +1364,7 @@
|
|
|
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 @@
|
|
|
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 @@
|
|
|
1569
1577
|
}
|
|
1570
1578
|
}
|
|
1571
1579
|
if (typeof id !== "string" && typeof id !== "number") {
|
|
1572
|
-
throw fail
|
|
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 @@
|
|
|
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
|
}
|
|
@@ -1622,10 +1630,10 @@
|
|
|
1622
1630
|
{
|
|
1623
1631
|
if (this.state !== NodeLifeCycle.INITIALIZING) {
|
|
1624
1632
|
// istanbul ignore next
|
|
1625
|
-
throw fail
|
|
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 @@
|
|
|
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 @@
|
|
|
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();
|
|
@@ -1745,20 +1753,20 @@
|
|
|
1745
1753
|
{
|
|
1746
1754
|
if (!subpath) {
|
|
1747
1755
|
// istanbul ignore next
|
|
1748
|
-
throw fail
|
|
1756
|
+
throw fail("assertion failed: subpath expected");
|
|
1749
1757
|
}
|
|
1750
1758
|
if (!newParent) {
|
|
1751
1759
|
// istanbul ignore next
|
|
1752
|
-
throw fail
|
|
1760
|
+
throw fail("assertion failed: new parent expected");
|
|
1753
1761
|
}
|
|
1754
1762
|
if (this.parent && parentChanged) {
|
|
1755
|
-
throw fail
|
|
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
|
|
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
|
-
throw fail
|
|
1769
|
+
throw fail("A state tree cannot be made part of another state tree as long as their environments are different.");
|
|
1762
1770
|
}
|
|
1763
1771
|
}
|
|
1764
1772
|
if (parentChanged) {
|
|
@@ -1814,7 +1822,7 @@
|
|
|
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
|
}
|
|
@@ -1864,7 +1872,7 @@
|
|
|
1864
1872
|
var error = this._getAssertAliveError(context);
|
|
1865
1873
|
switch (livelinessChecking) {
|
|
1866
1874
|
case "error":
|
|
1867
|
-
throw fail
|
|
1875
|
+
throw fail(error);
|
|
1868
1876
|
case "warn":
|
|
1869
1877
|
warnError(error);
|
|
1870
1878
|
}
|
|
@@ -1887,9 +1895,9 @@
|
|
|
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 @@
|
|
|
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 @@
|
|
|
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 @@
|
|
|
1950
1958
|
value: function (context) {
|
|
1951
1959
|
this.assertAlive(context);
|
|
1952
1960
|
if (!this.isRunningAction() && this.isProtected) {
|
|
1953
|
-
throw fail
|
|
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 @@
|
|
|
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", {
|
|
@@ -2017,7 +2025,7 @@
|
|
|
2017
2025
|
writable: true,
|
|
2018
2026
|
value: function () {
|
|
2019
2027
|
if (!this.isAlive)
|
|
2020
|
-
throw fail
|
|
2028
|
+
throw fail("Error while detaching, node is not alive.");
|
|
2021
2029
|
this.clearParent();
|
|
2022
2030
|
}
|
|
2023
2031
|
});
|
|
@@ -2065,7 +2073,7 @@
|
|
|
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 @@
|
|
|
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 @@
|
|
|
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 @@
|
|
|
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 @@
|
|
|
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 @@
|
|
|
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 @@
|
|
|
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,10 +2158,10 @@
|
|
|
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
|
-
throw fail
|
|
2164
|
+
throw fail("cannot add a disposer when it is already registered for execution");
|
|
2157
2165
|
}
|
|
2158
2166
|
});
|
|
2159
2167
|
Object.defineProperty(ObjectNode.prototype, "removeDisposer", {
|
|
@@ -2161,10 +2169,10 @@
|
|
|
2161
2169
|
configurable: true,
|
|
2162
2170
|
writable: true,
|
|
2163
2171
|
value: function (disposer) {
|
|
2164
|
-
if (!this._internalEventsHas("dispose" /* Dispose */, disposer)) {
|
|
2165
|
-
throw fail
|
|
2172
|
+
if (!this._internalEventsHas("dispose" /* InternalEvents.Dispose */, disposer)) {
|
|
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 @@
|
|
|
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
|
});
|
|
@@ -2408,7 +2416,7 @@
|
|
|
2408
2416
|
writable: true,
|
|
2409
2417
|
value: function (node, applyPostProcess) {
|
|
2410
2418
|
// istanbul ignore next
|
|
2411
|
-
throw fail
|
|
2419
|
+
throw fail("unimplemented method");
|
|
2412
2420
|
}
|
|
2413
2421
|
});
|
|
2414
2422
|
Object.defineProperty(BaseType.prototype, "isAssignableFrom", {
|
|
@@ -2446,7 +2454,7 @@
|
|
|
2446
2454
|
Object.defineProperty(BaseType.prototype, "Type", {
|
|
2447
2455
|
get: function () {
|
|
2448
2456
|
// istanbul ignore next
|
|
2449
|
-
throw fail
|
|
2457
|
+
throw fail("Factory.Type should not be actually called. It is just a Type signature that can be used at compile time with Typescript, by using `typeof type.Type`");
|
|
2450
2458
|
},
|
|
2451
2459
|
enumerable: false,
|
|
2452
2460
|
configurable: true
|
|
@@ -2454,7 +2462,7 @@
|
|
|
2454
2462
|
Object.defineProperty(BaseType.prototype, "TypeWithoutSTN", {
|
|
2455
2463
|
get: function () {
|
|
2456
2464
|
// istanbul ignore next
|
|
2457
|
-
throw fail
|
|
2465
|
+
throw fail("Factory.TypeWithoutSTN should not be actually called. It is just a Type signature that can be used at compile time with Typescript, by using `typeof type.TypeWithoutSTN`");
|
|
2458
2466
|
},
|
|
2459
2467
|
enumerable: false,
|
|
2460
2468
|
configurable: true
|
|
@@ -2462,7 +2470,7 @@
|
|
|
2462
2470
|
Object.defineProperty(BaseType.prototype, "SnapshotType", {
|
|
2463
2471
|
get: function () {
|
|
2464
2472
|
// istanbul ignore next
|
|
2465
|
-
throw fail
|
|
2473
|
+
throw fail("Factory.SnapshotType should not be actually called. It is just a Type signature that can be used at compile time with Typescript, by using `typeof type.SnapshotType`");
|
|
2466
2474
|
},
|
|
2467
2475
|
enumerable: false,
|
|
2468
2476
|
configurable: true
|
|
@@ -2470,7 +2478,7 @@
|
|
|
2470
2478
|
Object.defineProperty(BaseType.prototype, "CreationType", {
|
|
2471
2479
|
get: function () {
|
|
2472
2480
|
// istanbul ignore next
|
|
2473
|
-
throw fail
|
|
2481
|
+
throw fail("Factory.CreationType should not be actually called. It is just a Type signature that can be used at compile time with Typescript, by using `typeof type.CreationType`");
|
|
2474
2482
|
},
|
|
2475
2483
|
enumerable: false,
|
|
2476
2484
|
configurable: true
|
|
@@ -2915,11 +2923,11 @@
|
|
|
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 @@
|
|
|
2960
2968
|
function baseApplyAction(target, action) {
|
|
2961
2969
|
var resolvedTarget = tryResolve(target, action.path || "");
|
|
2962
2970
|
if (!resolvedTarget)
|
|
2963
|
-
throw fail
|
|
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 @@
|
|
|
2970
2978
|
return applySnapshot.call(null, resolvedTarget, action.args[0]);
|
|
2971
2979
|
}
|
|
2972
2980
|
if (!(typeof resolvedTarget[action.name] === "function"))
|
|
2973
|
-
throw fail
|
|
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 @@
|
|
|
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 @@
|
|
|
3331
3339
|
{
|
|
3332
3340
|
if (!nextInvoked && !abortInvoked) {
|
|
3333
3341
|
var node2 = getStateTreeNode(call.tree);
|
|
3334
|
-
throw fail
|
|
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
|
|
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 @@
|
|
|
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 @@
|
|
|
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 @@
|
|
|
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
|
: "")
|
|
@@ -3482,14 +3490,14 @@
|
|
|
3482
3490
|
function typecheck(type, value) {
|
|
3483
3491
|
var errors = type.validate(value, [{ path: "", type: type }]);
|
|
3484
3492
|
if (errors.length > 0) {
|
|
3485
|
-
throw fail
|
|
3493
|
+
throw fail(validationErrorsToString(type, value, errors));
|
|
3486
3494
|
}
|
|
3487
3495
|
}
|
|
3488
3496
|
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 @@
|
|
|
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", {
|
|
@@ -3553,7 +3561,7 @@
|
|
|
3553
3561
|
}
|
|
3554
3562
|
var set = this.cache.get(identifier);
|
|
3555
3563
|
if (set.indexOf(node) !== -1)
|
|
3556
|
-
throw fail
|
|
3564
|
+
throw fail("Already registered");
|
|
3557
3565
|
set.push(node);
|
|
3558
3566
|
if (lastCacheUpdate) {
|
|
3559
3567
|
this.updateLastCacheModificationPerId(identifier);
|
|
@@ -3652,9 +3660,9 @@
|
|
|
3652
3660
|
case 1:
|
|
3653
3661
|
return matches[0];
|
|
3654
3662
|
default:
|
|
3655
|
-
throw fail
|
|
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 @@
|
|
|
3670
3678
|
if (existingNode) {
|
|
3671
3679
|
if (existingNode.parent) {
|
|
3672
3680
|
// istanbul ignore next
|
|
3673
|
-
throw fail
|
|
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 @@
|
|
|
3733
3741
|
function getStateTreeNode(value) {
|
|
3734
3742
|
if (!isStateTreeNode(value)) {
|
|
3735
3743
|
// istanbul ignore next
|
|
3736
|
-
throw fail
|
|
3744
|
+
throw fail("Value ".concat(value, " is no MST Node"));
|
|
3737
3745
|
}
|
|
3738
3746
|
return value.$treenode;
|
|
3739
3747
|
}
|
|
@@ -3759,7 +3767,7 @@
|
|
|
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
|
|
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 @@
|
|
|
3816
3824
|
}
|
|
3817
3825
|
}
|
|
3818
3826
|
}
|
|
3819
|
-
throw fail
|
|
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) {
|
|
@@ -3892,7 +3900,7 @@
|
|
|
3892
3900
|
* @internal
|
|
3893
3901
|
* @hidden
|
|
3894
3902
|
*/
|
|
3895
|
-
function fail
|
|
3903
|
+
function fail(message) {
|
|
3896
3904
|
if (message === void 0) { message = "Illegal state"; }
|
|
3897
3905
|
return new Error("[mobx-state-tree] " + message);
|
|
3898
3906
|
}
|
|
@@ -4132,7 +4140,7 @@
|
|
|
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 @@
|
|
|
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
|
});
|
|
@@ -4267,7 +4275,7 @@
|
|
|
4267
4275
|
* @hidden
|
|
4268
4276
|
*/
|
|
4269
4277
|
function warnError(msg) {
|
|
4270
|
-
console.warn(new Error("[mobx-state-tree] "
|
|
4278
|
+
console.warn(new Error("[mobx-state-tree] ".concat(msg)));
|
|
4271
4279
|
}
|
|
4272
4280
|
/**
|
|
4273
4281
|
* @internal
|
|
@@ -4277,7 +4285,7 @@
|
|
|
4277
4285
|
{
|
|
4278
4286
|
if (!fn(value)) {
|
|
4279
4287
|
// istanbul ignore next
|
|
4280
|
-
throw fail
|
|
4288
|
+
throw fail("expected ".concat(typeName, " as argument ").concat(asArray(argNumber).join(" or "), ", got ").concat(value, " instead"));
|
|
4281
4289
|
}
|
|
4282
4290
|
}
|
|
4283
4291
|
}
|
|
@@ -4295,10 +4303,10 @@
|
|
|
4295
4303
|
function assertIsNumber(value, argNumber, min, max) {
|
|
4296
4304
|
assertArg(value, function (n) { return typeof n === "number"; }, "number", argNumber);
|
|
4297
4305
|
if (min !== undefined) {
|
|
4298
|
-
assertArg(value, function (n) { return n >= min; }, "number greater than "
|
|
4306
|
+
assertArg(value, function (n) { return n >= min; }, "number greater than ".concat(min), argNumber);
|
|
4299
4307
|
}
|
|
4300
4308
|
if (max !== undefined) {
|
|
4301
|
-
assertArg(value, function (n) { return n <= max; }, "number lesser than "
|
|
4309
|
+
assertArg(value, function (n) { return n <= max; }, "number lesser than ".concat(max), argNumber);
|
|
4302
4310
|
}
|
|
4303
4311
|
}
|
|
4304
4312
|
/**
|
|
@@ -4377,7 +4385,7 @@
|
|
|
4377
4385
|
}
|
|
4378
4386
|
return __generator(this, function (_a) {
|
|
4379
4387
|
switch (_a.label) {
|
|
4380
|
-
case 0: return [4 /*yield*/, p.apply(void 0,
|
|
4388
|
+
case 0: return [4 /*yield*/, p.apply(void 0, __spreadArray([], __read(args), false))];
|
|
4381
4389
|
case 1: return [2 /*return*/, (_a.sent())];
|
|
4382
4390
|
}
|
|
4383
4391
|
});
|
|
@@ -4422,11 +4430,11 @@
|
|
|
4422
4430
|
var runId = getNextActionId();
|
|
4423
4431
|
var parentContext = getCurrentActionContext();
|
|
4424
4432
|
if (!parentContext) {
|
|
4425
|
-
throw fail
|
|
4433
|
+
throw fail("a mst flow must always have a parent context");
|
|
4426
4434
|
}
|
|
4427
4435
|
var parentActionContext = getParentActionContext(parentContext);
|
|
4428
4436
|
if (!parentActionContext) {
|
|
4429
|
-
throw fail
|
|
4437
|
+
throw fail("a mst flow must always have a parent action context");
|
|
4430
4438
|
}
|
|
4431
4439
|
var contextBase = {
|
|
4432
4440
|
name: name,
|
|
@@ -4434,7 +4442,7 @@
|
|
|
4434
4442
|
tree: parentContext.tree,
|
|
4435
4443
|
context: parentContext.context,
|
|
4436
4444
|
parentId: parentContext.id,
|
|
4437
|
-
allParentIds:
|
|
4445
|
+
allParentIds: __spreadArray(__spreadArray([], __read(parentContext.allParentIds), false), [parentContext.id], false),
|
|
4438
4446
|
rootId: parentContext.rootId,
|
|
4439
4447
|
parentEvent: parentContext,
|
|
4440
4448
|
parentActionEvent: parentActionContext
|
|
@@ -4497,7 +4505,7 @@
|
|
|
4497
4505
|
// TODO: support more type of values? See https://github.com/tj/co/blob/249bbdc72da24ae44076afd716349d2089b31c4c/index.js#L100
|
|
4498
4506
|
if (!ret.value || typeof ret.value.then !== "function") {
|
|
4499
4507
|
// istanbul ignore next
|
|
4500
|
-
throw fail
|
|
4508
|
+
throw fail("Only promises can be yielded to `async`, got: " + ret);
|
|
4501
4509
|
}
|
|
4502
4510
|
return ret.value.then(onFulfilled, onRejected);
|
|
4503
4511
|
}
|
|
@@ -4513,7 +4521,7 @@
|
|
|
4513
4521
|
*/
|
|
4514
4522
|
function splitPatch(patch) {
|
|
4515
4523
|
if (!("oldValue" in patch))
|
|
4516
|
-
throw fail
|
|
4524
|
+
throw fail("Patches without `oldValue` field cannot be inversed");
|
|
4517
4525
|
return [stripPatch(patch), invertPatch(patch)];
|
|
4518
4526
|
}
|
|
4519
4527
|
/**
|
|
@@ -4614,7 +4622,7 @@
|
|
|
4614
4622
|
stringStartsWith(path, "./") ||
|
|
4615
4623
|
stringStartsWith(path, "../");
|
|
4616
4624
|
if (!valid) {
|
|
4617
|
-
throw fail
|
|
4625
|
+
throw fail("a json path must be either rooted, empty or relative, but got '".concat(path, "'"));
|
|
4618
4626
|
}
|
|
4619
4627
|
// '/a/b/c' -> ["a", "b", "c"]
|
|
4620
4628
|
// '../../b/c' -> ["..", "..", "b", "c"]
|
|
@@ -4660,7 +4668,7 @@
|
|
|
4660
4668
|
configurable: true,
|
|
4661
4669
|
writable: true,
|
|
4662
4670
|
value: function () {
|
|
4663
|
-
return "snapshotProcessor("
|
|
4671
|
+
return "snapshotProcessor(".concat(this._subtype.describe(), ")");
|
|
4664
4672
|
}
|
|
4665
4673
|
});
|
|
4666
4674
|
Object.defineProperty(SnapshotProcessor.prototype, "preProcessSnapshot", {
|
|
@@ -4962,28 +4970,28 @@
|
|
|
4962
4970
|
writable: true,
|
|
4963
4971
|
value: function (value) {
|
|
4964
4972
|
if (!value)
|
|
4965
|
-
throw fail
|
|
4973
|
+
throw fail("Map.put cannot be used to set empty values");
|
|
4966
4974
|
if (isStateTreeNode(value)) {
|
|
4967
4975
|
var node = getStateTreeNode(value);
|
|
4968
4976
|
{
|
|
4969
4977
|
if (!node.identifierAttribute) {
|
|
4970
|
-
throw fail
|
|
4978
|
+
throw fail(needsIdentifierError);
|
|
4971
4979
|
}
|
|
4972
4980
|
}
|
|
4973
4981
|
if (node.identifier === null) {
|
|
4974
|
-
throw fail
|
|
4982
|
+
throw fail(needsIdentifierError);
|
|
4975
4983
|
}
|
|
4976
4984
|
this.set(node.identifier, value);
|
|
4977
4985
|
return value;
|
|
4978
4986
|
}
|
|
4979
4987
|
else if (!isMutable(value)) {
|
|
4980
|
-
throw fail
|
|
4988
|
+
throw fail("Map.put can only be used to store complex values");
|
|
4981
4989
|
}
|
|
4982
4990
|
else {
|
|
4983
4991
|
var mapNode = getStateTreeNode(this);
|
|
4984
4992
|
var mapType = mapNode.type;
|
|
4985
4993
|
if (mapType.identifierMode !== MapIdentifierMode.YES) {
|
|
4986
|
-
throw fail
|
|
4994
|
+
throw fail(needsIdentifierError);
|
|
4987
4995
|
}
|
|
4988
4996
|
var idAttr = mapType.mapIdentifierAttribute;
|
|
4989
4997
|
var id = value[idAttr];
|
|
@@ -5076,7 +5084,7 @@
|
|
|
5076
5084
|
if (!type.identifierAttribute)
|
|
5077
5085
|
return current;
|
|
5078
5086
|
if (current && current !== type.identifierAttribute) {
|
|
5079
|
-
throw fail
|
|
5087
|
+
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"));
|
|
5080
5088
|
}
|
|
5081
5089
|
return type.identifierAttribute;
|
|
5082
5090
|
}, undefined);
|
|
@@ -5155,7 +5163,7 @@
|
|
|
5155
5163
|
value: function (node, key) {
|
|
5156
5164
|
var childNode = node.storedValue.get("" + key);
|
|
5157
5165
|
if (!childNode)
|
|
5158
|
-
throw fail
|
|
5166
|
+
throw fail("Not a child " + key);
|
|
5159
5167
|
return childNode;
|
|
5160
5168
|
}
|
|
5161
5169
|
});
|
|
@@ -5200,7 +5208,7 @@
|
|
|
5200
5208
|
if (this.identifierMode === MapIdentifierMode.YES && node instanceof ObjectNode) {
|
|
5201
5209
|
var identifier = node.identifier;
|
|
5202
5210
|
if (identifier !== expected)
|
|
5203
|
-
throw fail
|
|
5211
|
+
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, "'"));
|
|
5204
5212
|
}
|
|
5205
5213
|
}
|
|
5206
5214
|
});
|
|
@@ -5372,7 +5380,7 @@
|
|
|
5372
5380
|
* @returns
|
|
5373
5381
|
*/
|
|
5374
5382
|
function map(subtype) {
|
|
5375
|
-
return new MapType("Map<string, "
|
|
5383
|
+
return new MapType("Map<string, ".concat(subtype.name, ">"), subtype);
|
|
5376
5384
|
}
|
|
5377
5385
|
/**
|
|
5378
5386
|
* Returns if a given value represents a map type.
|
|
@@ -5498,7 +5506,7 @@
|
|
|
5498
5506
|
var index = Number(key);
|
|
5499
5507
|
if (index < node.storedValue.length)
|
|
5500
5508
|
return node.storedValue[index];
|
|
5501
|
-
throw fail
|
|
5509
|
+
throw fail("Not a child: " + key);
|
|
5502
5510
|
}
|
|
5503
5511
|
});
|
|
5504
5512
|
Object.defineProperty(ArrayType.prototype, "willChange", {
|
|
@@ -5689,7 +5697,7 @@
|
|
|
5689
5697
|
*/
|
|
5690
5698
|
function array(subtype) {
|
|
5691
5699
|
assertIsType(subtype, 1);
|
|
5692
|
-
return new ArrayType(subtype.name
|
|
5700
|
+
return new ArrayType("".concat(subtype.name, "[]"), subtype);
|
|
5693
5701
|
}
|
|
5694
5702
|
function reconcileArrayChildren(parent, childType, oldNodes, newValues, newPaths) {
|
|
5695
5703
|
var nothingChanged = true;
|
|
@@ -5723,7 +5731,7 @@
|
|
|
5723
5731
|
// check if already belongs to the same parent. if so, avoid pushing item in. only swapping can occur.
|
|
5724
5732
|
if (isStateTreeNode(newValue) && getStateTreeNode(newValue).parent === parent) {
|
|
5725
5733
|
// this node is owned by this parent, but not in the reconcilable set, so it must be double
|
|
5726
|
-
throw fail
|
|
5734
|
+
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, "'"));
|
|
5727
5735
|
}
|
|
5728
5736
|
nothingChanged = false;
|
|
5729
5737
|
var newNode = valueAsNode(childType, parent, newPath, newValue);
|
|
@@ -5839,7 +5847,7 @@
|
|
|
5839
5847
|
var alreadySeenKeys = new Set();
|
|
5840
5848
|
keysList.forEach(function (key) {
|
|
5841
5849
|
if (alreadySeenKeys.has(key)) {
|
|
5842
|
-
throw fail
|
|
5850
|
+
throw fail("".concat(key, " is declared twice in the model. Model should not contain the same keys"));
|
|
5843
5851
|
}
|
|
5844
5852
|
alreadySeenKeys.add(key);
|
|
5845
5853
|
});
|
|
@@ -5847,17 +5855,17 @@
|
|
|
5847
5855
|
return keysList.reduce(function (props, key) {
|
|
5848
5856
|
// warn if user intended a HOOK
|
|
5849
5857
|
if (key in Hook) {
|
|
5850
|
-
throw fail
|
|
5858
|
+
throw fail("Hook '".concat(key, "' was defined as property. Hooks should be defined as part of the actions"));
|
|
5851
5859
|
}
|
|
5852
5860
|
// the user intended to use a view
|
|
5853
5861
|
var descriptor = Object.getOwnPropertyDescriptor(declaredProps, key);
|
|
5854
5862
|
if ("get" in descriptor) {
|
|
5855
|
-
throw fail
|
|
5863
|
+
throw fail("Getters are not supported as properties. Please use views instead");
|
|
5856
5864
|
}
|
|
5857
5865
|
// undefined and null are not valid
|
|
5858
5866
|
var value = descriptor.value;
|
|
5859
5867
|
if (value === null || value === undefined) {
|
|
5860
|
-
throw fail
|
|
5868
|
+
throw fail("The default value of an attribute cannot be null or undefined as the type cannot be inferred. Did you mean `types.maybe(someType)`?");
|
|
5861
5869
|
}
|
|
5862
5870
|
// its a primitive, convert to its type
|
|
5863
5871
|
else if (isPrimitive(value)) {
|
|
@@ -5874,14 +5882,14 @@
|
|
|
5874
5882
|
else if (isType(value)) ;
|
|
5875
5883
|
// its a function, maybe the user wanted a view?
|
|
5876
5884
|
else if (typeof value === "function") {
|
|
5877
|
-
throw fail
|
|
5885
|
+
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?"));
|
|
5878
5886
|
}
|
|
5879
5887
|
// no other complex values
|
|
5880
5888
|
else if (typeof value === "object") {
|
|
5881
|
-
throw fail
|
|
5889
|
+
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."));
|
|
5882
5890
|
}
|
|
5883
5891
|
else {
|
|
5884
|
-
throw fail
|
|
5892
|
+
throw fail("Invalid type definition for property '".concat(key, "', cannot infer a type from a value like '").concat(value, "' (").concat(typeof value, ")"));
|
|
5885
5893
|
}
|
|
5886
5894
|
return props;
|
|
5887
5895
|
}, declaredProps);
|
|
@@ -5994,7 +6002,7 @@
|
|
|
5994
6002
|
this.forAllProps(function (propName, propType) {
|
|
5995
6003
|
if (propType.flags & TypeFlags.Identifier) {
|
|
5996
6004
|
if (identifierAttribute)
|
|
5997
|
-
throw fail
|
|
6005
|
+
throw fail("Cannot define property '".concat(propName, "' as object identifier, property '").concat(identifierAttribute, "' is already defined as identifier property"));
|
|
5998
6006
|
identifierAttribute = propName;
|
|
5999
6007
|
}
|
|
6000
6008
|
});
|
|
@@ -6035,15 +6043,15 @@
|
|
|
6035
6043
|
value: function (self, actions) {
|
|
6036
6044
|
// check if return is correct
|
|
6037
6045
|
if (!isPlainObject(actions))
|
|
6038
|
-
throw fail
|
|
6046
|
+
throw fail("actions initializer should return a plain object containing actions");
|
|
6039
6047
|
// bind actions to the object created
|
|
6040
6048
|
Object.keys(actions).forEach(function (name) {
|
|
6041
6049
|
// warn if preprocessor was given
|
|
6042
6050
|
if (name === PRE_PROCESS_SNAPSHOT)
|
|
6043
|
-
throw fail
|
|
6051
|
+
throw fail("Cannot define action '".concat(PRE_PROCESS_SNAPSHOT, "', it should be defined using 'type.preProcessSnapshot(fn)' instead"));
|
|
6044
6052
|
// warn if postprocessor was given
|
|
6045
6053
|
if (name === POST_PROCESS_SNAPSHOT)
|
|
6046
|
-
throw fail
|
|
6054
|
+
throw fail("Cannot define action '".concat(POST_PROCESS_SNAPSHOT, "', it should be defined using 'type.postProcessSnapshot(fn)' instead"));
|
|
6047
6055
|
var action2 = actions[name];
|
|
6048
6056
|
// apply hook composition
|
|
6049
6057
|
var baseAction = self[name];
|
|
@@ -6073,7 +6081,7 @@
|
|
|
6073
6081
|
value: function (fn) {
|
|
6074
6082
|
var _this = this;
|
|
6075
6083
|
if (typeof fn !== "function") {
|
|
6076
|
-
throw fail
|
|
6084
|
+
throw fail("You passed an ".concat(typeof fn, " to volatile state as an argument, when function is expected"));
|
|
6077
6085
|
}
|
|
6078
6086
|
var stateInitializer = function (self) {
|
|
6079
6087
|
_this.instantiateVolatileState(self, fn(self));
|
|
@@ -6089,7 +6097,7 @@
|
|
|
6089
6097
|
value: function (self, state) {
|
|
6090
6098
|
// check views return
|
|
6091
6099
|
if (!isPlainObject(state))
|
|
6092
|
-
throw fail
|
|
6100
|
+
throw fail("volatile state initializer should return a plain object containing state");
|
|
6093
6101
|
mobx.set(self, state);
|
|
6094
6102
|
}
|
|
6095
6103
|
});
|
|
@@ -6102,7 +6110,7 @@
|
|
|
6102
6110
|
var initializer = function (self) {
|
|
6103
6111
|
var _a = fn(self), actions = _a.actions, views = _a.views, state = _a.state, rest = __rest(_a, ["actions", "views", "state"]);
|
|
6104
6112
|
for (var key in rest)
|
|
6105
|
-
throw fail
|
|
6113
|
+
throw fail("The `extend` function should return an object with a subset of the fields 'actions', 'views' and 'state'. Found invalid key '".concat(key, "'"));
|
|
6106
6114
|
if (state)
|
|
6107
6115
|
_this.instantiateVolatileState(self, state);
|
|
6108
6116
|
if (views)
|
|
@@ -6134,7 +6142,7 @@
|
|
|
6134
6142
|
value: function (self, views) {
|
|
6135
6143
|
// check views return
|
|
6136
6144
|
if (!isPlainObject(views))
|
|
6137
|
-
throw fail
|
|
6145
|
+
throw fail("views initializer should return a plain object containing views");
|
|
6138
6146
|
Object.getOwnPropertyNames(views).forEach(function (key) {
|
|
6139
6147
|
var _a;
|
|
6140
6148
|
// is this a computed property?
|
|
@@ -6147,7 +6155,7 @@
|
|
|
6147
6155
|
(addHiddenWritableProp)(self, key, descriptor.value);
|
|
6148
6156
|
}
|
|
6149
6157
|
else {
|
|
6150
|
-
throw fail
|
|
6158
|
+
throw fail("A view member should either be a function or getter based property");
|
|
6151
6159
|
}
|
|
6152
6160
|
});
|
|
6153
6161
|
}
|
|
@@ -6263,11 +6271,11 @@
|
|
|
6263
6271
|
value: function (node, key) {
|
|
6264
6272
|
var _a;
|
|
6265
6273
|
if (!(key in this.properties))
|
|
6266
|
-
throw fail
|
|
6274
|
+
throw fail("Not a value property: " + key);
|
|
6267
6275
|
var adm = mobx._getAdministration(node.storedValue, key);
|
|
6268
6276
|
var childNode = (_a = adm.raw) === null || _a === void 0 ? void 0 : _a.call(adm);
|
|
6269
6277
|
if (!childNode)
|
|
6270
|
-
throw fail
|
|
6278
|
+
throw fail("Node not available for property " + key);
|
|
6271
6279
|
return childNode;
|
|
6272
6280
|
}
|
|
6273
6281
|
});
|
|
@@ -6286,7 +6294,7 @@
|
|
|
6286
6294
|
atom.reportObserved();
|
|
6287
6295
|
}
|
|
6288
6296
|
catch (e) {
|
|
6289
|
-
throw fail
|
|
6297
|
+
throw fail("".concat(name, " property is declared twice"));
|
|
6290
6298
|
}
|
|
6291
6299
|
res[name] = _this.getChildNode(node, name).snapshot;
|
|
6292
6300
|
});
|
|
@@ -6314,7 +6322,7 @@
|
|
|
6314
6322
|
writable: true,
|
|
6315
6323
|
value: function (node, subpath, patch) {
|
|
6316
6324
|
if (!(patch.op === "replace" || patch.op === "add")) {
|
|
6317
|
-
throw fail
|
|
6325
|
+
throw fail("object does not support operation ".concat(patch.op));
|
|
6318
6326
|
}
|
|
6319
6327
|
node.storedValue[subpath] = patch.value;
|
|
6320
6328
|
}
|
|
@@ -6426,7 +6434,7 @@
|
|
|
6426
6434
|
args[_i] = arguments[_i];
|
|
6427
6435
|
}
|
|
6428
6436
|
if (typeof args[0] !== "string" && args[1]) {
|
|
6429
|
-
throw fail
|
|
6437
|
+
throw fail("Model creation failed. First argument must be a string when two arguments are provided");
|
|
6430
6438
|
}
|
|
6431
6439
|
var name = typeof args[0] === "string" ? args.shift() : "AnonymousModel";
|
|
6432
6440
|
var properties = args.shift() || {};
|
|
@@ -6546,7 +6554,7 @@
|
|
|
6546
6554
|
return typeCheckSuccess();
|
|
6547
6555
|
}
|
|
6548
6556
|
var typeName = this.name === "Date" ? "Date or a unix milliseconds timestamp" : this.name;
|
|
6549
|
-
return typeCheckFailure(context, value, "Value is not a "
|
|
6557
|
+
return typeCheckFailure(context, value, "Value is not a ".concat(typeName));
|
|
6550
6558
|
}
|
|
6551
6559
|
});
|
|
6552
6560
|
return CoreType;
|
|
@@ -6673,7 +6681,7 @@
|
|
|
6673
6681
|
if (value instanceof Date)
|
|
6674
6682
|
return DatePrimitive;
|
|
6675
6683
|
}
|
|
6676
|
-
throw fail
|
|
6684
|
+
throw fail("Cannot determine primitive type from value " + value);
|
|
6677
6685
|
}
|
|
6678
6686
|
/**
|
|
6679
6687
|
* Returns if a given value represents a primitive type.
|
|
@@ -6739,7 +6747,7 @@
|
|
|
6739
6747
|
if (isPrimitive(value) && value === this.value) {
|
|
6740
6748
|
return typeCheckSuccess();
|
|
6741
6749
|
}
|
|
6742
|
-
return typeCheckFailure(context, value, "Value is not a literal "
|
|
6750
|
+
return typeCheckFailure(context, value, "Value is not a literal ".concat(JSON.stringify(this.value)));
|
|
6743
6751
|
}
|
|
6744
6752
|
});
|
|
6745
6753
|
return Literal;
|
|
@@ -6921,7 +6929,7 @@
|
|
|
6921
6929
|
assertIsString(option, i + 1);
|
|
6922
6930
|
});
|
|
6923
6931
|
}
|
|
6924
|
-
var type = union.apply(void 0,
|
|
6932
|
+
var type = union.apply(void 0, __spreadArray([], __read(realOptions.map(function (option) { return literal("" + option); })), false));
|
|
6925
6933
|
if (typeof name === "string")
|
|
6926
6934
|
type.name = name;
|
|
6927
6935
|
return type;
|
|
@@ -6993,7 +7001,7 @@
|
|
|
6993
7001
|
value: function (parent, subpath, environment, initialValue) {
|
|
6994
7002
|
var type = this.determineType(initialValue, undefined);
|
|
6995
7003
|
if (!type)
|
|
6996
|
-
throw fail
|
|
7004
|
+
throw fail("No matching type for union " + this.describe()); // can happen in prod builds
|
|
6997
7005
|
return type.instantiate(parent, subpath, environment, initialValue);
|
|
6998
7006
|
}
|
|
6999
7007
|
});
|
|
@@ -7004,7 +7012,7 @@
|
|
|
7004
7012
|
value: function (current, newValue, parent, subpath) {
|
|
7005
7013
|
var type = this.determineType(newValue, current.getReconciliationType());
|
|
7006
7014
|
if (!type)
|
|
7007
|
-
throw fail
|
|
7015
|
+
throw fail("No matching type for union " + this.describe()); // can happen in prod builds
|
|
7008
7016
|
return type.reconcile(current, newValue, parent, subpath);
|
|
7009
7017
|
}
|
|
7010
7018
|
});
|
|
@@ -7017,7 +7025,7 @@
|
|
|
7017
7025
|
if (this._dispatcher) {
|
|
7018
7026
|
return this._dispatcher(value);
|
|
7019
7027
|
}
|
|
7020
|
-
// find the most
|
|
7028
|
+
// find the most accommodating type
|
|
7021
7029
|
// if we are using reconciliation try the current node type first (fix for #1045)
|
|
7022
7030
|
if (reconcileCurrentType) {
|
|
7023
7031
|
if (reconcileCurrentType.is(value)) {
|
|
@@ -7081,7 +7089,7 @@
|
|
|
7081
7089
|
otherTypes[_i - 1] = arguments[_i];
|
|
7082
7090
|
}
|
|
7083
7091
|
var options = isType(optionsOrType) ? undefined : optionsOrType;
|
|
7084
|
-
var types = isType(optionsOrType) ?
|
|
7092
|
+
var types = isType(optionsOrType) ? __spreadArray([optionsOrType], __read(otherTypes), false) : otherTypes;
|
|
7085
7093
|
var name = "(" + types.map(function (type) { return type.name; }).join(" | ") + ")";
|
|
7086
7094
|
// check all options
|
|
7087
7095
|
{
|
|
@@ -7219,7 +7227,7 @@
|
|
|
7219
7227
|
function checkOptionalPreconditions(type, defaultValueOrFunction) {
|
|
7220
7228
|
// make sure we never pass direct instances
|
|
7221
7229
|
if (typeof defaultValueOrFunction !== "function" && isStateTreeNode(defaultValueOrFunction)) {
|
|
7222
|
-
throw fail
|
|
7230
|
+
throw fail("default value cannot be an instance, pass a snapshot or a function that creates an instance/snapshot instead");
|
|
7223
7231
|
}
|
|
7224
7232
|
assertIsType(type, 1);
|
|
7225
7233
|
{
|
|
@@ -7358,10 +7366,10 @@
|
|
|
7358
7366
|
throw e;
|
|
7359
7367
|
}
|
|
7360
7368
|
if (mustSucceed && t === undefined)
|
|
7361
|
-
throw fail
|
|
7369
|
+
throw fail("Late type seems to be used too early, the definition (still) returns undefined");
|
|
7362
7370
|
if (t) {
|
|
7363
7371
|
if (!isType(t))
|
|
7364
|
-
throw fail
|
|
7372
|
+
throw fail("Failed to determine subtype, make sure types.late returns a type definition.");
|
|
7365
7373
|
this._subType = t;
|
|
7366
7374
|
}
|
|
7367
7375
|
}
|
|
@@ -7443,12 +7451,12 @@
|
|
|
7443
7451
|
* @returns
|
|
7444
7452
|
*/
|
|
7445
7453
|
function late(nameOrType, maybeType) {
|
|
7446
|
-
var name = typeof nameOrType === "string" ? nameOrType : "late("
|
|
7454
|
+
var name = typeof nameOrType === "string" ? nameOrType : "late(".concat(nameOrType.toString(), ")");
|
|
7447
7455
|
var type = typeof nameOrType === "string" ? maybeType : nameOrType;
|
|
7448
7456
|
// checks that the type is actually a late type
|
|
7449
7457
|
{
|
|
7450
7458
|
if (!(typeof type === "function" && type.length === 0))
|
|
7451
|
-
throw fail
|
|
7459
|
+
throw fail("Invalid late type, expected a function with zero arguments that returns a type, got: " +
|
|
7452
7460
|
type);
|
|
7453
7461
|
}
|
|
7454
7462
|
return new Late(name, type);
|
|
@@ -7515,7 +7523,7 @@
|
|
|
7515
7523
|
node.parent.applyPatches([
|
|
7516
7524
|
{
|
|
7517
7525
|
op: "replace",
|
|
7518
|
-
path: "/"
|
|
7526
|
+
path: "/".concat(node.subpath),
|
|
7519
7527
|
value: node.snapshot
|
|
7520
7528
|
}
|
|
7521
7529
|
]);
|
|
@@ -7529,7 +7537,7 @@
|
|
|
7529
7537
|
configurable: true,
|
|
7530
7538
|
writable: true,
|
|
7531
7539
|
value: function () {
|
|
7532
|
-
return "<lazy "
|
|
7540
|
+
return "<lazy ".concat(this.name, ">");
|
|
7533
7541
|
}
|
|
7534
7542
|
});
|
|
7535
7543
|
Object.defineProperty(Lazy.prototype, "instantiate", {
|
|
@@ -7583,7 +7591,7 @@
|
|
|
7583
7591
|
var Frozen = /** @class */ (function (_super) {
|
|
7584
7592
|
__extends(Frozen, _super);
|
|
7585
7593
|
function Frozen(subType) {
|
|
7586
|
-
var _this = _super.call(this, subType ? "frozen("
|
|
7594
|
+
var _this = _super.call(this, subType ? "frozen(".concat(subType.name, ")") : "frozen") || this;
|
|
7587
7595
|
Object.defineProperty(_this, "subType", {
|
|
7588
7596
|
enumerable: true,
|
|
7589
7597
|
configurable: true,
|
|
@@ -7731,15 +7739,15 @@
|
|
|
7731
7739
|
else if (isStateTreeNode(value)) {
|
|
7732
7740
|
var targetNode = getStateTreeNode(value);
|
|
7733
7741
|
if (!targetNode.identifierAttribute)
|
|
7734
|
-
throw fail
|
|
7742
|
+
throw fail("Can only store references with a defined identifier attribute.");
|
|
7735
7743
|
var id = targetNode.unnormalizedIdentifier;
|
|
7736
7744
|
if (id === null || id === undefined) {
|
|
7737
|
-
throw fail
|
|
7745
|
+
throw fail("Can only store references to tree nodes with a defined identifier.");
|
|
7738
7746
|
}
|
|
7739
7747
|
this.identifier = id;
|
|
7740
7748
|
}
|
|
7741
7749
|
else {
|
|
7742
|
-
throw fail
|
|
7750
|
+
throw fail("Can only store references to tree nodes or identifiers, got: '".concat(value, "'"));
|
|
7743
7751
|
}
|
|
7744
7752
|
}
|
|
7745
7753
|
Object.defineProperty(StoredReference.prototype, "updateResolvedReference", {
|
|
@@ -7756,7 +7764,7 @@
|
|
|
7756
7764
|
// reference was initialized with the identifier of the target
|
|
7757
7765
|
var target = root.identifierCache.resolve(targetType, normalizedId);
|
|
7758
7766
|
if (!target) {
|
|
7759
|
-
throw new InvalidReferenceError("[mobx-state-tree] Failed to resolve reference '"
|
|
7767
|
+
throw new InvalidReferenceError("[mobx-state-tree] Failed to resolve reference '".concat(this.identifier, "' to type '").concat(this.targetType.name, "' (from node: ").concat(node.path, ")"));
|
|
7760
7768
|
}
|
|
7761
7769
|
this.resolvedReference = {
|
|
7762
7770
|
node: target,
|
|
@@ -7795,7 +7803,7 @@
|
|
|
7795
7803
|
var BaseReferenceType = /** @class */ (function (_super) {
|
|
7796
7804
|
__extends(BaseReferenceType, _super);
|
|
7797
7805
|
function BaseReferenceType(targetType, onInvalidated) {
|
|
7798
|
-
var _this = _super.call(this, "reference("
|
|
7806
|
+
var _this = _super.call(this, "reference(".concat(targetType.name, ")")) || this;
|
|
7799
7807
|
Object.defineProperty(_this, "targetType", {
|
|
7800
7808
|
enumerable: true,
|
|
7801
7809
|
configurable: true,
|
|
@@ -8121,7 +8129,7 @@
|
|
|
8121
8129
|
{
|
|
8122
8130
|
if (arguments.length === 2 && typeof arguments[1] === "string") {
|
|
8123
8131
|
// istanbul ignore next
|
|
8124
|
-
throw fail
|
|
8132
|
+
throw fail("References with base path are no longer supported. Please remove the base path.");
|
|
8125
8133
|
}
|
|
8126
8134
|
}
|
|
8127
8135
|
var getSetOptions = options ? options : undefined;
|
|
@@ -8131,7 +8139,7 @@
|
|
|
8131
8139
|
if (getSetOptions && (getSetOptions.get || getSetOptions.set)) {
|
|
8132
8140
|
{
|
|
8133
8141
|
if (!getSetOptions.get || !getSetOptions.set) {
|
|
8134
|
-
throw fail
|
|
8142
|
+
throw fail("reference options must either contain both a 'get' and a 'set' method or none of them");
|
|
8135
8143
|
}
|
|
8136
8144
|
}
|
|
8137
8145
|
return new CustomReferenceType(subType, {
|
|
@@ -8209,7 +8217,7 @@
|
|
|
8209
8217
|
writable: true,
|
|
8210
8218
|
value: function (parent, subpath, environment, initialValue) {
|
|
8211
8219
|
if (!parent || !(parent.type instanceof ModelType))
|
|
8212
|
-
throw fail
|
|
8220
|
+
throw fail("Identifier types can only be instantiated as direct child of a model type");
|
|
8213
8221
|
return createScalarNode(this, parent, subpath, environment, initialValue);
|
|
8214
8222
|
}
|
|
8215
8223
|
});
|
|
@@ -8220,7 +8228,7 @@
|
|
|
8220
8228
|
value: function (current, newValue, parent, subpath) {
|
|
8221
8229
|
// we don't consider detaching here since identifier are scalar nodes, and scalar nodes cannot be detached
|
|
8222
8230
|
if (current.storedValue !== newValue)
|
|
8223
|
-
throw fail
|
|
8231
|
+
throw fail("Tried to change identifier from '".concat(current.storedValue, "' to '").concat(newValue, "'. Changing identifiers is not allowed."));
|
|
8224
8232
|
current.setParent(parent, subpath);
|
|
8225
8233
|
return current;
|
|
8226
8234
|
}
|
|
@@ -8231,7 +8239,7 @@
|
|
|
8231
8239
|
writable: true,
|
|
8232
8240
|
value: function (value, context) {
|
|
8233
8241
|
if (typeof value !== this.validType) {
|
|
8234
|
-
return typeCheckFailure(context, value, "Value is not a valid "
|
|
8242
|
+
return typeCheckFailure(context, value, "Value is not a valid ".concat(this.describe(), ", expected a ").concat(this.validType));
|
|
8235
8243
|
}
|
|
8236
8244
|
return typeCheckSuccess();
|
|
8237
8245
|
}
|
|
@@ -8442,7 +8450,7 @@
|
|
|
8442
8450
|
return typeCheckSuccess();
|
|
8443
8451
|
var typeError = this.options.getValidationMessage(value);
|
|
8444
8452
|
if (typeError) {
|
|
8445
|
-
return typeCheckFailure(context, value, "Invalid value for type '"
|
|
8453
|
+
return typeCheckFailure(context, value, "Invalid value for type '".concat(this.name, "': ").concat(typeError));
|
|
8446
8454
|
}
|
|
8447
8455
|
return typeCheckSuccess();
|
|
8448
8456
|
}
|
|
@@ -8606,4 +8614,4 @@
|
|
|
8606
8614
|
|
|
8607
8615
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
8608
8616
|
|
|
8609
|
-
}))
|
|
8617
|
+
}));
|