mobx-state-tree 6.0.0-pre.2 → 6.0.0
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/README.md +0 -1
- package/dist/index.d.ts +3 -3
- package/dist/mobx-state-tree.js +147 -124
- package/dist/mobx-state-tree.min.js +1 -1
- package/dist/mobx-state-tree.module.js +147 -124
- package/dist/mobx-state-tree.umd.js +147 -124
- package/dist/mobx-state-tree.umd.min.js +1 -1
- package/package.json +7 -14
|
@@ -356,7 +356,7 @@
|
|
|
356
356
|
assertIsStateTreeNode(target, 1);
|
|
357
357
|
var node = getStateTreeNode(target);
|
|
358
358
|
if (!node.isRoot)
|
|
359
|
-
throw
|
|
359
|
+
throw new MstError("`protect` can only be invoked on root nodes");
|
|
360
360
|
node.isProtectionEnabled = true;
|
|
361
361
|
}
|
|
362
362
|
/**
|
|
@@ -388,7 +388,7 @@
|
|
|
388
388
|
assertIsStateTreeNode(target, 1);
|
|
389
389
|
var node = getStateTreeNode(target);
|
|
390
390
|
if (!node.isRoot)
|
|
391
|
-
throw
|
|
391
|
+
throw new MstError("`unprotect` can only be invoked on root nodes");
|
|
392
392
|
node.isProtectionEnabled = false;
|
|
393
393
|
}
|
|
394
394
|
/**
|
|
@@ -471,7 +471,7 @@
|
|
|
471
471
|
return parent.storedValue;
|
|
472
472
|
parent = parent.parent;
|
|
473
473
|
}
|
|
474
|
-
throw
|
|
474
|
+
throw new MstError("Failed to find the parent of ".concat(getStateTreeNode(target), " at depth ").concat(depth));
|
|
475
475
|
}
|
|
476
476
|
/**
|
|
477
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
|
|
@@ -509,7 +509,7 @@
|
|
|
509
509
|
return parent.storedValue;
|
|
510
510
|
parent = parent.parent;
|
|
511
511
|
}
|
|
512
|
-
throw
|
|
512
|
+
throw new MstError("Failed to find the parent of ".concat(getStateTreeNode(target), " of a given type"));
|
|
513
513
|
}
|
|
514
514
|
/**
|
|
515
515
|
* Given an object in a model tree, returns the root object of that tree.
|
|
@@ -626,7 +626,7 @@
|
|
|
626
626
|
}
|
|
627
627
|
}
|
|
628
628
|
else {
|
|
629
|
-
throw
|
|
629
|
+
throw new MstError("The reference to be checked is not one of node, null or undefined");
|
|
630
630
|
}
|
|
631
631
|
}
|
|
632
632
|
catch (e) {
|
|
@@ -654,7 +654,7 @@
|
|
|
654
654
|
return checkIfAlive ? isAlive(node) : true;
|
|
655
655
|
}
|
|
656
656
|
else {
|
|
657
|
-
throw
|
|
657
|
+
throw new MstError("The reference to be checked is not one of node, null or undefined");
|
|
658
658
|
}
|
|
659
659
|
}
|
|
660
660
|
catch (e) {
|
|
@@ -811,7 +811,7 @@
|
|
|
811
811
|
var node = getStateTreeNode(target);
|
|
812
812
|
var env = node.root.environment;
|
|
813
813
|
if (!env)
|
|
814
|
-
throw
|
|
814
|
+
throw new MstError("Failed to find the environment of ".concat(node, " ").concat(node.path));
|
|
815
815
|
return env;
|
|
816
816
|
}
|
|
817
817
|
/**
|
|
@@ -825,7 +825,7 @@
|
|
|
825
825
|
// check all arguments
|
|
826
826
|
{
|
|
827
827
|
if (!isStateTreeNode(target))
|
|
828
|
-
|
|
828
|
+
throw new MstError("expected first argument to be a mobx-state-tree node, got " + target + " instead");
|
|
829
829
|
}
|
|
830
830
|
var node = getStateTreeNode(target);
|
|
831
831
|
var env = node.root.environment;
|
|
@@ -894,14 +894,18 @@
|
|
|
894
894
|
reflected.volatile.push(key);
|
|
895
895
|
return;
|
|
896
896
|
}
|
|
897
|
-
if (descriptor.value.
|
|
898
|
-
reflected.actions.push(key);
|
|
899
|
-
if (descriptor.value._isFlowAction === true)
|
|
897
|
+
if (descriptor.value._isFlowAction === true) {
|
|
900
898
|
reflected.flowActions.push(key);
|
|
901
|
-
|
|
899
|
+
}
|
|
900
|
+
if (descriptor.value._isMSTAction === true) {
|
|
901
|
+
reflected.actions.push(key);
|
|
902
|
+
}
|
|
903
|
+
else if (mobx.isObservableProp(target, key)) {
|
|
902
904
|
reflected.volatile.push(key);
|
|
903
|
-
|
|
905
|
+
}
|
|
906
|
+
else {
|
|
904
907
|
reflected.views.push(key);
|
|
908
|
+
}
|
|
905
909
|
});
|
|
906
910
|
return reflected;
|
|
907
911
|
}
|
|
@@ -1255,7 +1259,7 @@
|
|
|
1255
1259
|
{
|
|
1256
1260
|
if (!this.isAlive) {
|
|
1257
1261
|
// istanbul ignore next
|
|
1258
|
-
throw
|
|
1262
|
+
throw new MstError("assertion failed: cannot finalize the creation of a node that is already dead");
|
|
1259
1263
|
}
|
|
1260
1264
|
}
|
|
1261
1265
|
// goal: afterCreate hooks runs depth-first. After attach runs parent first, so on afterAttach the parent has completed already
|
|
@@ -1326,7 +1330,7 @@
|
|
|
1326
1330
|
get: function () {
|
|
1327
1331
|
// future optimization: store root ref in the node and maintain it
|
|
1328
1332
|
if (!this.parent)
|
|
1329
|
-
throw
|
|
1333
|
+
throw new MstError("This scalar node is not part of a tree");
|
|
1330
1334
|
return this.parent.root;
|
|
1331
1335
|
},
|
|
1332
1336
|
enumerable: false,
|
|
@@ -1345,15 +1349,15 @@
|
|
|
1345
1349
|
{
|
|
1346
1350
|
if (!subpath) {
|
|
1347
1351
|
// istanbul ignore next
|
|
1348
|
-
throw
|
|
1352
|
+
throw new MstError("assertion failed: subpath expected");
|
|
1349
1353
|
}
|
|
1350
1354
|
if (!newParent) {
|
|
1351
1355
|
// istanbul ignore next
|
|
1352
|
-
throw
|
|
1356
|
+
throw new MstError("assertion failed: parent expected");
|
|
1353
1357
|
}
|
|
1354
1358
|
if (parentChanged) {
|
|
1355
1359
|
// istanbul ignore next
|
|
1356
|
-
throw
|
|
1360
|
+
throw new MstError("assertion failed: scalar nodes cannot change their parent");
|
|
1357
1361
|
}
|
|
1358
1362
|
}
|
|
1359
1363
|
this.environment = undefined; // use parent's
|
|
@@ -1432,6 +1436,21 @@
|
|
|
1432
1436
|
ScalarNode.prototype.die = mobx.action(ScalarNode.prototype.die);
|
|
1433
1437
|
|
|
1434
1438
|
var nextNodeId = 1;
|
|
1439
|
+
var ObservableInstanceLifecycle;
|
|
1440
|
+
(function (ObservableInstanceLifecycle) {
|
|
1441
|
+
// the actual observable instance has not been created yet
|
|
1442
|
+
ObservableInstanceLifecycle[ObservableInstanceLifecycle["UNINITIALIZED"] = 0] = "UNINITIALIZED";
|
|
1443
|
+
// the actual observable instance is being created
|
|
1444
|
+
ObservableInstanceLifecycle[ObservableInstanceLifecycle["CREATING"] = 1] = "CREATING";
|
|
1445
|
+
// the actual observable instance has been created
|
|
1446
|
+
ObservableInstanceLifecycle[ObservableInstanceLifecycle["CREATED"] = 2] = "CREATED";
|
|
1447
|
+
})(ObservableInstanceLifecycle || (ObservableInstanceLifecycle = {}));
|
|
1448
|
+
var InternalEvents;
|
|
1449
|
+
(function (InternalEvents) {
|
|
1450
|
+
InternalEvents["Dispose"] = "dispose";
|
|
1451
|
+
InternalEvents["Patch"] = "patch";
|
|
1452
|
+
InternalEvents["Snapshot"] = "snapshot";
|
|
1453
|
+
})(InternalEvents || (InternalEvents = {}));
|
|
1435
1454
|
var snapshotReactionOptions = {
|
|
1436
1455
|
onError: function (e) {
|
|
1437
1456
|
throw e;
|
|
@@ -1527,7 +1546,7 @@
|
|
|
1527
1546
|
enumerable: true,
|
|
1528
1547
|
configurable: true,
|
|
1529
1548
|
writable: true,
|
|
1530
|
-
value:
|
|
1549
|
+
value: ObservableInstanceLifecycle.UNINITIALIZED
|
|
1531
1550
|
});
|
|
1532
1551
|
Object.defineProperty(_this, "_childNodes", {
|
|
1533
1552
|
enumerable: true,
|
|
@@ -1594,7 +1613,7 @@
|
|
|
1594
1613
|
}
|
|
1595
1614
|
}
|
|
1596
1615
|
if (typeof id !== "string" && typeof id !== "number") {
|
|
1597
|
-
throw
|
|
1616
|
+
throw new MstError("Instance identifier '".concat(_this.identifierAttribute, "' for type '").concat(_this.type.name, "' must be a string or a number"));
|
|
1598
1617
|
}
|
|
1599
1618
|
// normalize internal identifier to string
|
|
1600
1619
|
_this.identifier = normalizeIdentifier(id);
|
|
@@ -1632,7 +1651,7 @@
|
|
|
1632
1651
|
writable: true,
|
|
1633
1652
|
value: function (fireHooks) {
|
|
1634
1653
|
if (fireHooks === void 0) { fireHooks = true; }
|
|
1635
|
-
if (this._observableInstanceState ===
|
|
1654
|
+
if (this._observableInstanceState === ObservableInstanceLifecycle.UNINITIALIZED) {
|
|
1636
1655
|
this.createObservableInstance(fireHooks);
|
|
1637
1656
|
}
|
|
1638
1657
|
}
|
|
@@ -1647,10 +1666,10 @@
|
|
|
1647
1666
|
{
|
|
1648
1667
|
if (this.state !== NodeLifeCycle.INITIALIZING) {
|
|
1649
1668
|
// istanbul ignore next
|
|
1650
|
-
throw
|
|
1669
|
+
throw new MstError("assertion failed: the creation of the observable instance must be done on the initializing phase");
|
|
1651
1670
|
}
|
|
1652
1671
|
}
|
|
1653
|
-
this._observableInstanceState =
|
|
1672
|
+
this._observableInstanceState = ObservableInstanceLifecycle.CREATING;
|
|
1654
1673
|
// make sure the parent chain is created as well
|
|
1655
1674
|
// array with parent chain from parent to child
|
|
1656
1675
|
var parentChain = [];
|
|
@@ -1660,7 +1679,7 @@
|
|
|
1660
1679
|
// this is done to avoid traversing the whole tree to the root when using
|
|
1661
1680
|
// the same reference again
|
|
1662
1681
|
while (parent &&
|
|
1663
|
-
parent._observableInstanceState ===
|
|
1682
|
+
parent._observableInstanceState === ObservableInstanceLifecycle.UNINITIALIZED) {
|
|
1664
1683
|
parentChain.unshift(parent);
|
|
1665
1684
|
parent = parent.parent;
|
|
1666
1685
|
}
|
|
@@ -1694,7 +1713,7 @@
|
|
|
1694
1713
|
finally {
|
|
1695
1714
|
this._isRunningAction = false;
|
|
1696
1715
|
}
|
|
1697
|
-
this._observableInstanceState =
|
|
1716
|
+
this._observableInstanceState = ObservableInstanceLifecycle.CREATED;
|
|
1698
1717
|
this._snapshotComputed.trackAndCompute();
|
|
1699
1718
|
if (this.isRoot)
|
|
1700
1719
|
this._addSnapshotReaction();
|
|
@@ -1770,20 +1789,20 @@
|
|
|
1770
1789
|
{
|
|
1771
1790
|
if (!subpath) {
|
|
1772
1791
|
// istanbul ignore next
|
|
1773
|
-
throw
|
|
1792
|
+
throw new MstError("assertion failed: subpath expected");
|
|
1774
1793
|
}
|
|
1775
1794
|
if (!newParent) {
|
|
1776
1795
|
// istanbul ignore next
|
|
1777
|
-
throw
|
|
1796
|
+
throw new MstError("assertion failed: new parent expected");
|
|
1778
1797
|
}
|
|
1779
1798
|
if (this.parent && parentChanged) {
|
|
1780
|
-
throw
|
|
1799
|
+
throw new MstError("A node cannot exists twice in the state tree. Failed to add ".concat(this, " to path '").concat(newParent.path, "/").concat(subpath, "'."));
|
|
1781
1800
|
}
|
|
1782
1801
|
if (!this.parent && newParent.root === this) {
|
|
1783
|
-
throw
|
|
1802
|
+
throw new MstError("A state tree is not allowed to contain itself. Cannot assign ".concat(this, " to path '").concat(newParent.path, "/").concat(subpath, "'"));
|
|
1784
1803
|
}
|
|
1785
1804
|
if (!this.parent && !!this.environment && this.environment !== newParent.root.environment) {
|
|
1786
|
-
throw
|
|
1805
|
+
throw new MstError("A state tree cannot be made part of another state tree as long as their environments are different.");
|
|
1787
1806
|
}
|
|
1788
1807
|
}
|
|
1789
1808
|
if (parentChanged) {
|
|
@@ -1839,7 +1858,7 @@
|
|
|
1839
1858
|
value: function () {
|
|
1840
1859
|
if (!this.isAlive)
|
|
1841
1860
|
return this._snapshotUponDeath;
|
|
1842
|
-
return this._observableInstanceState ===
|
|
1861
|
+
return this._observableInstanceState === ObservableInstanceLifecycle.CREATED
|
|
1843
1862
|
? this._getActualSnapshot()
|
|
1844
1863
|
: this._getCachedInitialSnapshot();
|
|
1845
1864
|
}
|
|
@@ -1889,7 +1908,7 @@
|
|
|
1889
1908
|
var error = this._getAssertAliveError(context);
|
|
1890
1909
|
switch (livelinessChecking) {
|
|
1891
1910
|
case "error":
|
|
1892
|
-
throw
|
|
1911
|
+
throw new MstError(error);
|
|
1893
1912
|
case "warn":
|
|
1894
1913
|
warnError(error);
|
|
1895
1914
|
}
|
|
@@ -1927,7 +1946,7 @@
|
|
|
1927
1946
|
});
|
|
1928
1947
|
this._autoUnbox = false;
|
|
1929
1948
|
try {
|
|
1930
|
-
return this._observableInstanceState ===
|
|
1949
|
+
return this._observableInstanceState === ObservableInstanceLifecycle.CREATED
|
|
1931
1950
|
? this.type.getChildNode(this, subpath)
|
|
1932
1951
|
: this._childNodes[subpath];
|
|
1933
1952
|
}
|
|
@@ -1944,7 +1963,7 @@
|
|
|
1944
1963
|
this.assertAlive(EMPTY_OBJECT);
|
|
1945
1964
|
this._autoUnbox = false;
|
|
1946
1965
|
try {
|
|
1947
|
-
return this._observableInstanceState ===
|
|
1966
|
+
return this._observableInstanceState === ObservableInstanceLifecycle.CREATED
|
|
1948
1967
|
? this.type.getChildren(this)
|
|
1949
1968
|
: convertChildNodesToArray(this._childNodes);
|
|
1950
1969
|
}
|
|
@@ -1975,7 +1994,7 @@
|
|
|
1975
1994
|
value: function (context) {
|
|
1976
1995
|
this.assertAlive(context);
|
|
1977
1996
|
if (!this.isRunningAction() && this.isProtected) {
|
|
1978
|
-
throw
|
|
1997
|
+
throw new MstError("Cannot modify '".concat(this, "', the object is protected and can only be modified by using an action."));
|
|
1979
1998
|
}
|
|
1980
1999
|
}
|
|
1981
2000
|
});
|
|
@@ -2042,7 +2061,7 @@
|
|
|
2042
2061
|
writable: true,
|
|
2043
2062
|
value: function () {
|
|
2044
2063
|
if (!this.isAlive)
|
|
2045
|
-
throw
|
|
2064
|
+
throw new MstError("Error while detaching, node is not alive.");
|
|
2046
2065
|
this.clearParent();
|
|
2047
2066
|
}
|
|
2048
2067
|
});
|
|
@@ -2090,7 +2109,7 @@
|
|
|
2090
2109
|
configurable: true,
|
|
2091
2110
|
writable: true,
|
|
2092
2111
|
value: function () {
|
|
2093
|
-
if (this._observableInstanceState ===
|
|
2112
|
+
if (this._observableInstanceState === ObservableInstanceLifecycle.UNINITIALIZED) {
|
|
2094
2113
|
return;
|
|
2095
2114
|
}
|
|
2096
2115
|
this.getChildren().forEach(function (node) {
|
|
@@ -2099,8 +2118,8 @@
|
|
|
2099
2118
|
// beforeDestroy should run before the disposers since else we could end up in a situation where
|
|
2100
2119
|
// a disposer added with addDisposer at this stage (beforeDestroy) is actually never released
|
|
2101
2120
|
this.baseAboutToDie();
|
|
2102
|
-
this._internalEventsEmit(
|
|
2103
|
-
this._internalEventsClear(
|
|
2121
|
+
this._internalEventsEmit(InternalEvents.Dispose);
|
|
2122
|
+
this._internalEventsClear(InternalEvents.Dispose);
|
|
2104
2123
|
}
|
|
2105
2124
|
});
|
|
2106
2125
|
Object.defineProperty(ObjectNode.prototype, "finalizeDeath", {
|
|
@@ -2126,7 +2145,7 @@
|
|
|
2126
2145
|
writable: true,
|
|
2127
2146
|
value: function (onChange) {
|
|
2128
2147
|
this._addSnapshotReaction();
|
|
2129
|
-
return this._internalEventsRegister(
|
|
2148
|
+
return this._internalEventsRegister(InternalEvents.Snapshot, onChange);
|
|
2130
2149
|
}
|
|
2131
2150
|
});
|
|
2132
2151
|
Object.defineProperty(ObjectNode.prototype, "emitSnapshot", {
|
|
@@ -2134,7 +2153,7 @@
|
|
|
2134
2153
|
configurable: true,
|
|
2135
2154
|
writable: true,
|
|
2136
2155
|
value: function (snapshot) {
|
|
2137
|
-
this._internalEventsEmit(
|
|
2156
|
+
this._internalEventsEmit(InternalEvents.Snapshot, snapshot);
|
|
2138
2157
|
}
|
|
2139
2158
|
});
|
|
2140
2159
|
Object.defineProperty(ObjectNode.prototype, "onPatch", {
|
|
@@ -2142,7 +2161,7 @@
|
|
|
2142
2161
|
configurable: true,
|
|
2143
2162
|
writable: true,
|
|
2144
2163
|
value: function (handler) {
|
|
2145
|
-
return this._internalEventsRegister(
|
|
2164
|
+
return this._internalEventsRegister(InternalEvents.Patch, handler);
|
|
2146
2165
|
}
|
|
2147
2166
|
});
|
|
2148
2167
|
Object.defineProperty(ObjectNode.prototype, "emitPatch", {
|
|
@@ -2150,12 +2169,12 @@
|
|
|
2150
2169
|
configurable: true,
|
|
2151
2170
|
writable: true,
|
|
2152
2171
|
value: function (basePatch, source) {
|
|
2153
|
-
if (this._internalEventsHasSubscribers(
|
|
2172
|
+
if (this._internalEventsHasSubscribers(InternalEvents.Patch)) {
|
|
2154
2173
|
// calculate the relative path of the patch
|
|
2155
2174
|
var path = source.path.substr(this.path.length) + (basePatch.path ? "/" + basePatch.path : "");
|
|
2156
2175
|
var localizedPatch = extend({}, basePatch, { path: path });
|
|
2157
2176
|
var _a = __read(splitPatch(localizedPatch), 2), patch = _a[0], reversePatch = _a[1];
|
|
2158
|
-
this._internalEventsEmit(
|
|
2177
|
+
this._internalEventsEmit(InternalEvents.Patch, patch, reversePatch);
|
|
2159
2178
|
}
|
|
2160
2179
|
if (this.parent)
|
|
2161
2180
|
this.parent.emitPatch(basePatch, source);
|
|
@@ -2166,7 +2185,7 @@
|
|
|
2166
2185
|
configurable: true,
|
|
2167
2186
|
writable: true,
|
|
2168
2187
|
value: function (disposer) {
|
|
2169
|
-
return this._internalEventsHas(
|
|
2188
|
+
return this._internalEventsHas(InternalEvents.Dispose, disposer);
|
|
2170
2189
|
}
|
|
2171
2190
|
});
|
|
2172
2191
|
Object.defineProperty(ObjectNode.prototype, "addDisposer", {
|
|
@@ -2175,10 +2194,10 @@
|
|
|
2175
2194
|
writable: true,
|
|
2176
2195
|
value: function (disposer) {
|
|
2177
2196
|
if (!this.hasDisposer(disposer)) {
|
|
2178
|
-
this._internalEventsRegister(
|
|
2197
|
+
this._internalEventsRegister(InternalEvents.Dispose, disposer, true);
|
|
2179
2198
|
return;
|
|
2180
2199
|
}
|
|
2181
|
-
throw
|
|
2200
|
+
throw new MstError("cannot add a disposer when it is already registered for execution");
|
|
2182
2201
|
}
|
|
2183
2202
|
});
|
|
2184
2203
|
Object.defineProperty(ObjectNode.prototype, "removeDisposer", {
|
|
@@ -2186,10 +2205,10 @@
|
|
|
2186
2205
|
configurable: true,
|
|
2187
2206
|
writable: true,
|
|
2188
2207
|
value: function (disposer) {
|
|
2189
|
-
if (!this._internalEventsHas(
|
|
2190
|
-
throw
|
|
2208
|
+
if (!this._internalEventsHas(InternalEvents.Dispose, disposer)) {
|
|
2209
|
+
throw new MstError("cannot remove a disposer which was never registered for execution");
|
|
2191
2210
|
}
|
|
2192
|
-
this._internalEventsUnregister(
|
|
2211
|
+
this._internalEventsUnregister(InternalEvents.Dispose, disposer);
|
|
2193
2212
|
}
|
|
2194
2213
|
});
|
|
2195
2214
|
Object.defineProperty(ObjectNode.prototype, "removeMiddleware", {
|
|
@@ -2433,7 +2452,7 @@
|
|
|
2433
2452
|
writable: true,
|
|
2434
2453
|
value: function (node, applyPostProcess) {
|
|
2435
2454
|
// istanbul ignore next
|
|
2436
|
-
throw
|
|
2455
|
+
throw new MstError("unimplemented method");
|
|
2437
2456
|
}
|
|
2438
2457
|
});
|
|
2439
2458
|
Object.defineProperty(BaseType.prototype, "isAssignableFrom", {
|
|
@@ -2471,7 +2490,7 @@
|
|
|
2471
2490
|
Object.defineProperty(BaseType.prototype, "Type", {
|
|
2472
2491
|
get: function () {
|
|
2473
2492
|
// istanbul ignore next
|
|
2474
|
-
throw
|
|
2493
|
+
throw new MstError("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`");
|
|
2475
2494
|
},
|
|
2476
2495
|
enumerable: false,
|
|
2477
2496
|
configurable: true
|
|
@@ -2479,7 +2498,7 @@
|
|
|
2479
2498
|
Object.defineProperty(BaseType.prototype, "TypeWithoutSTN", {
|
|
2480
2499
|
get: function () {
|
|
2481
2500
|
// istanbul ignore next
|
|
2482
|
-
throw
|
|
2501
|
+
throw new MstError("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`");
|
|
2483
2502
|
},
|
|
2484
2503
|
enumerable: false,
|
|
2485
2504
|
configurable: true
|
|
@@ -2487,7 +2506,7 @@
|
|
|
2487
2506
|
Object.defineProperty(BaseType.prototype, "SnapshotType", {
|
|
2488
2507
|
get: function () {
|
|
2489
2508
|
// istanbul ignore next
|
|
2490
|
-
throw
|
|
2509
|
+
throw new MstError("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`");
|
|
2491
2510
|
},
|
|
2492
2511
|
enumerable: false,
|
|
2493
2512
|
configurable: true
|
|
@@ -2495,7 +2514,7 @@
|
|
|
2495
2514
|
Object.defineProperty(BaseType.prototype, "CreationType", {
|
|
2496
2515
|
get: function () {
|
|
2497
2516
|
// istanbul ignore next
|
|
2498
|
-
throw
|
|
2517
|
+
throw new MstError("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`");
|
|
2499
2518
|
},
|
|
2500
2519
|
enumerable: false,
|
|
2501
2520
|
configurable: true
|
|
@@ -2985,7 +3004,7 @@
|
|
|
2985
3004
|
function baseApplyAction(target, action) {
|
|
2986
3005
|
var resolvedTarget = tryResolve(target, action.path || "");
|
|
2987
3006
|
if (!resolvedTarget)
|
|
2988
|
-
throw
|
|
3007
|
+
throw new MstError("Invalid action path: ".concat(action.path || ""));
|
|
2989
3008
|
var node = getStateTreeNode(resolvedTarget);
|
|
2990
3009
|
// Reserved functions
|
|
2991
3010
|
if (action.name === "@APPLY_PATCHES") {
|
|
@@ -2995,7 +3014,7 @@
|
|
|
2995
3014
|
return applySnapshot.call(null, resolvedTarget, action.args[0]);
|
|
2996
3015
|
}
|
|
2997
3016
|
if (!(typeof resolvedTarget[action.name] === "function"))
|
|
2998
|
-
throw
|
|
3017
|
+
throw new MstError("Action '".concat(action.name, "' does not exist in '").concat(node.path, "'"));
|
|
2999
3018
|
return resolvedTarget[action.name].apply(resolvedTarget, action.args ? action.args.map(function (v) { return deserializeArgument(node, v); }) : []);
|
|
3000
3019
|
}
|
|
3001
3020
|
/**
|
|
@@ -3356,11 +3375,11 @@
|
|
|
3356
3375
|
{
|
|
3357
3376
|
if (!nextInvoked && !abortInvoked) {
|
|
3358
3377
|
var node2 = getStateTreeNode(call.tree);
|
|
3359
|
-
throw
|
|
3378
|
+
throw new MstError("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."));
|
|
3360
3379
|
}
|
|
3361
3380
|
else if (nextInvoked && abortInvoked) {
|
|
3362
3381
|
var node2 = getStateTreeNode(call.tree);
|
|
3363
|
-
throw
|
|
3382
|
+
throw new MstError("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."));
|
|
3364
3383
|
}
|
|
3365
3384
|
}
|
|
3366
3385
|
return result;
|
|
@@ -3507,7 +3526,7 @@
|
|
|
3507
3526
|
function typecheck(type, value) {
|
|
3508
3527
|
var errors = type.validate(value, [{ path: "", type: type }]);
|
|
3509
3528
|
if (errors.length > 0) {
|
|
3510
|
-
throw
|
|
3529
|
+
throw new MstError(validationErrorsToString(type, value, errors));
|
|
3511
3530
|
}
|
|
3512
3531
|
}
|
|
3513
3532
|
function validationErrorsToString(type, value, errors) {
|
|
@@ -3578,7 +3597,7 @@
|
|
|
3578
3597
|
}
|
|
3579
3598
|
var set = this.cache.get(identifier);
|
|
3580
3599
|
if (set.indexOf(node) !== -1)
|
|
3581
|
-
throw
|
|
3600
|
+
throw new MstError("Already registered");
|
|
3582
3601
|
set.push(node);
|
|
3583
3602
|
if (lastCacheUpdate) {
|
|
3584
3603
|
this.updateLastCacheModificationPerId(identifier);
|
|
@@ -3677,7 +3696,7 @@
|
|
|
3677
3696
|
case 1:
|
|
3678
3697
|
return matches[0];
|
|
3679
3698
|
default:
|
|
3680
|
-
throw
|
|
3699
|
+
throw new MstError("Cannot resolve a reference to type '".concat(type.name, "' with id: '").concat(identifier, "' unambigously, there are multiple candidates: ").concat(matches
|
|
3681
3700
|
.map(function (n) { return n.path; })
|
|
3682
3701
|
.join(", ")));
|
|
3683
3702
|
}
|
|
@@ -3695,7 +3714,7 @@
|
|
|
3695
3714
|
if (existingNode) {
|
|
3696
3715
|
if (existingNode.parent) {
|
|
3697
3716
|
// istanbul ignore next
|
|
3698
|
-
throw
|
|
3717
|
+
throw new MstError("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, "'"));
|
|
3699
3718
|
}
|
|
3700
3719
|
if (parent) {
|
|
3701
3720
|
existingNode.setParent(parent, subpath);
|
|
@@ -3758,7 +3777,7 @@
|
|
|
3758
3777
|
function getStateTreeNode(value) {
|
|
3759
3778
|
if (!isStateTreeNode(value)) {
|
|
3760
3779
|
// istanbul ignore next
|
|
3761
|
-
throw
|
|
3780
|
+
throw new MstError("Value ".concat(value, " is no MST Node"));
|
|
3762
3781
|
}
|
|
3763
3782
|
return value.$treenode;
|
|
3764
3783
|
}
|
|
@@ -3784,7 +3803,7 @@
|
|
|
3784
3803
|
function getRelativePathBetweenNodes(base, target) {
|
|
3785
3804
|
// PRE condition target is (a child of) base!
|
|
3786
3805
|
if (base.root !== target.root) {
|
|
3787
|
-
throw
|
|
3806
|
+
throw new MstError("Cannot calculate relative path: objects '".concat(base, "' and '").concat(target, "' are not part of the same object tree"));
|
|
3788
3807
|
}
|
|
3789
3808
|
var baseParts = splitJsonPath(base.path);
|
|
3790
3809
|
var targetParts = splitJsonPath(target.path);
|
|
@@ -3841,7 +3860,7 @@
|
|
|
3841
3860
|
}
|
|
3842
3861
|
}
|
|
3843
3862
|
}
|
|
3844
|
-
throw
|
|
3863
|
+
throw new MstError("Could not resolve '".concat(part, "' in path '").concat(joinJsonPath(pathParts.slice(0, i)) || "/", "' while resolving '").concat(joinJsonPath(pathParts), "'"));
|
|
3845
3864
|
}
|
|
3846
3865
|
}
|
|
3847
3866
|
catch (e) {
|
|
@@ -3917,10 +3936,14 @@
|
|
|
3917
3936
|
* @internal
|
|
3918
3937
|
* @hidden
|
|
3919
3938
|
*/
|
|
3920
|
-
function
|
|
3921
|
-
|
|
3922
|
-
|
|
3923
|
-
|
|
3939
|
+
var MstError = /** @class */ (function (_super) {
|
|
3940
|
+
__extends(MstError, _super);
|
|
3941
|
+
function MstError(message) {
|
|
3942
|
+
if (message === void 0) { message = "Illegal state"; }
|
|
3943
|
+
return _super.call(this, "[mobx-state-tree] ".concat(message)) || this;
|
|
3944
|
+
}
|
|
3945
|
+
return MstError;
|
|
3946
|
+
}(Error));
|
|
3924
3947
|
/**
|
|
3925
3948
|
* @internal
|
|
3926
3949
|
* @hidden
|
|
@@ -4302,7 +4325,7 @@
|
|
|
4302
4325
|
{
|
|
4303
4326
|
if (!fn(value)) {
|
|
4304
4327
|
// istanbul ignore next
|
|
4305
|
-
throw
|
|
4328
|
+
throw new MstError("expected ".concat(typeName, " as argument ").concat(asArray(argNumber).join(" or "), ", got ").concat(value, " instead"));
|
|
4306
4329
|
}
|
|
4307
4330
|
}
|
|
4308
4331
|
}
|
|
@@ -4447,11 +4470,11 @@
|
|
|
4447
4470
|
var runId = getNextActionId();
|
|
4448
4471
|
var parentContext = getCurrentActionContext();
|
|
4449
4472
|
if (!parentContext) {
|
|
4450
|
-
throw
|
|
4473
|
+
throw new MstError("a mst flow must always have a parent context");
|
|
4451
4474
|
}
|
|
4452
4475
|
var parentActionContext = getParentActionContext(parentContext);
|
|
4453
4476
|
if (!parentActionContext) {
|
|
4454
|
-
throw
|
|
4477
|
+
throw new MstError("a mst flow must always have a parent action context");
|
|
4455
4478
|
}
|
|
4456
4479
|
var contextBase = {
|
|
4457
4480
|
name: name,
|
|
@@ -4522,7 +4545,7 @@
|
|
|
4522
4545
|
// TODO: support more type of values? See https://github.com/tj/co/blob/249bbdc72da24ae44076afd716349d2089b31c4c/index.js#L100
|
|
4523
4546
|
if (!ret.value || typeof ret.value.then !== "function") {
|
|
4524
4547
|
// istanbul ignore next
|
|
4525
|
-
throw
|
|
4548
|
+
throw new MstError("Only promises can be yielded to `async`, got: " + ret);
|
|
4526
4549
|
}
|
|
4527
4550
|
return ret.value.then(onFulfilled, onRejected);
|
|
4528
4551
|
}
|
|
@@ -4538,7 +4561,7 @@
|
|
|
4538
4561
|
*/
|
|
4539
4562
|
function splitPatch(patch) {
|
|
4540
4563
|
if (!("oldValue" in patch))
|
|
4541
|
-
throw
|
|
4564
|
+
throw new MstError("Patches without `oldValue` field cannot be inversed");
|
|
4542
4565
|
return [stripPatch(patch), invertPatch(patch)];
|
|
4543
4566
|
}
|
|
4544
4567
|
/**
|
|
@@ -4639,7 +4662,7 @@
|
|
|
4639
4662
|
stringStartsWith(path, "./") ||
|
|
4640
4663
|
stringStartsWith(path, "../");
|
|
4641
4664
|
if (!valid) {
|
|
4642
|
-
throw
|
|
4665
|
+
throw new MstError("a json path must be either rooted, empty or relative, but got '".concat(path, "'"));
|
|
4643
4666
|
}
|
|
4644
4667
|
// '/a/b/c' -> ["a", "b", "c"]
|
|
4645
4668
|
// '../../b/c' -> ["..", "..", "b", "c"]
|
|
@@ -4894,11 +4917,11 @@
|
|
|
4894
4917
|
{
|
|
4895
4918
|
if (processors.postProcessor && typeof processors.postProcessor !== "function") {
|
|
4896
4919
|
// istanbul ignore next
|
|
4897
|
-
throw
|
|
4920
|
+
throw new MstError("postSnapshotProcessor must be a function");
|
|
4898
4921
|
}
|
|
4899
4922
|
if (processors.preProcessor && typeof processors.preProcessor !== "function") {
|
|
4900
4923
|
// istanbul ignore next
|
|
4901
|
-
throw
|
|
4924
|
+
throw new MstError("preSnapshotProcessor must be a function");
|
|
4902
4925
|
}
|
|
4903
4926
|
}
|
|
4904
4927
|
return new SnapshotProcessor(type, processors, name);
|
|
@@ -4987,28 +5010,28 @@
|
|
|
4987
5010
|
writable: true,
|
|
4988
5011
|
value: function (value) {
|
|
4989
5012
|
if (!value)
|
|
4990
|
-
throw
|
|
5013
|
+
throw new MstError("Map.put cannot be used to set empty values");
|
|
4991
5014
|
if (isStateTreeNode(value)) {
|
|
4992
5015
|
var node = getStateTreeNode(value);
|
|
4993
5016
|
{
|
|
4994
5017
|
if (!node.identifierAttribute) {
|
|
4995
|
-
throw
|
|
5018
|
+
throw new MstError(needsIdentifierError);
|
|
4996
5019
|
}
|
|
4997
5020
|
}
|
|
4998
5021
|
if (node.identifier === null) {
|
|
4999
|
-
throw
|
|
5022
|
+
throw new MstError(needsIdentifierError);
|
|
5000
5023
|
}
|
|
5001
5024
|
this.set(node.identifier, value);
|
|
5002
5025
|
return value;
|
|
5003
5026
|
}
|
|
5004
5027
|
else if (!isMutable(value)) {
|
|
5005
|
-
throw
|
|
5028
|
+
throw new MstError("Map.put can only be used to store complex values");
|
|
5006
5029
|
}
|
|
5007
5030
|
else {
|
|
5008
5031
|
var mapNode = getStateTreeNode(this);
|
|
5009
5032
|
var mapType = mapNode.type;
|
|
5010
5033
|
if (mapType.identifierMode !== MapIdentifierMode.YES) {
|
|
5011
|
-
throw
|
|
5034
|
+
throw new MstError(needsIdentifierError);
|
|
5012
5035
|
}
|
|
5013
5036
|
var idAttr = mapType.mapIdentifierAttribute;
|
|
5014
5037
|
var id = value[idAttr];
|
|
@@ -5101,7 +5124,7 @@
|
|
|
5101
5124
|
if (!type.identifierAttribute)
|
|
5102
5125
|
return current;
|
|
5103
5126
|
if (current && current !== type.identifierAttribute) {
|
|
5104
|
-
throw
|
|
5127
|
+
throw new MstError("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"));
|
|
5105
5128
|
}
|
|
5106
5129
|
return type.identifierAttribute;
|
|
5107
5130
|
}, undefined);
|
|
@@ -5180,7 +5203,7 @@
|
|
|
5180
5203
|
value: function (node, key) {
|
|
5181
5204
|
var childNode = node.storedValue.get("" + key);
|
|
5182
5205
|
if (!childNode)
|
|
5183
|
-
throw
|
|
5206
|
+
throw new MstError("Not a child " + key);
|
|
5184
5207
|
return childNode;
|
|
5185
5208
|
}
|
|
5186
5209
|
});
|
|
@@ -5225,7 +5248,7 @@
|
|
|
5225
5248
|
if (this.identifierMode === MapIdentifierMode.YES && node instanceof ObjectNode) {
|
|
5226
5249
|
var identifier = node.identifier;
|
|
5227
5250
|
if (identifier !== expected)
|
|
5228
|
-
throw
|
|
5251
|
+
throw new MstError("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, "'"));
|
|
5229
5252
|
}
|
|
5230
5253
|
}
|
|
5231
5254
|
});
|
|
@@ -5523,7 +5546,7 @@
|
|
|
5523
5546
|
var index = Number(key);
|
|
5524
5547
|
if (index < node.storedValue.length)
|
|
5525
5548
|
return node.storedValue[index];
|
|
5526
|
-
throw
|
|
5549
|
+
throw new MstError("Not a child: " + key);
|
|
5527
5550
|
}
|
|
5528
5551
|
});
|
|
5529
5552
|
Object.defineProperty(ArrayType.prototype, "willChange", {
|
|
@@ -5757,7 +5780,7 @@
|
|
|
5757
5780
|
// check if already belongs to the same parent. if so, avoid pushing item in. only swapping can occur.
|
|
5758
5781
|
if (isStateTreeNode(newValue) && getStateTreeNode(newValue).parent === parent) {
|
|
5759
5782
|
// this node is owned by this parent, but not in the reconcilable set, so it must be double
|
|
5760
|
-
throw
|
|
5783
|
+
throw new MstError("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, "'"));
|
|
5761
5784
|
}
|
|
5762
5785
|
nothingChanged = false;
|
|
5763
5786
|
var newNode = valueAsNode(childType, parent, newPath, newValue);
|
|
@@ -5873,7 +5896,7 @@
|
|
|
5873
5896
|
var alreadySeenKeys = new Set();
|
|
5874
5897
|
keysList.forEach(function (key) {
|
|
5875
5898
|
if (alreadySeenKeys.has(key)) {
|
|
5876
|
-
throw
|
|
5899
|
+
throw new MstError("".concat(key, " is declared twice in the model. Model should not contain the same keys"));
|
|
5877
5900
|
}
|
|
5878
5901
|
alreadySeenKeys.add(key);
|
|
5879
5902
|
});
|
|
@@ -5881,17 +5904,17 @@
|
|
|
5881
5904
|
return keysList.reduce(function (props, key) {
|
|
5882
5905
|
// warn if user intended a HOOK
|
|
5883
5906
|
if (key in Hook) {
|
|
5884
|
-
throw
|
|
5907
|
+
throw new MstError("Hook '".concat(key, "' was defined as property. Hooks should be defined as part of the actions"));
|
|
5885
5908
|
}
|
|
5886
5909
|
// the user intended to use a view
|
|
5887
5910
|
var descriptor = Object.getOwnPropertyDescriptor(declaredProps, key);
|
|
5888
5911
|
if ("get" in descriptor) {
|
|
5889
|
-
throw
|
|
5912
|
+
throw new MstError("Getters are not supported as properties. Please use views instead");
|
|
5890
5913
|
}
|
|
5891
5914
|
// undefined and null are not valid
|
|
5892
5915
|
var value = descriptor.value;
|
|
5893
5916
|
if (value === null || value === undefined) {
|
|
5894
|
-
throw
|
|
5917
|
+
throw new MstError("The default value of an attribute cannot be null or undefined as the type cannot be inferred. Did you mean `types.maybe(someType)`?");
|
|
5895
5918
|
}
|
|
5896
5919
|
// its a primitive, convert to its type
|
|
5897
5920
|
else if (isPrimitive(value)) {
|
|
@@ -5908,17 +5931,17 @@
|
|
|
5908
5931
|
else if (isType(value)) ;
|
|
5909
5932
|
// its a function, maybe the user wanted a view?
|
|
5910
5933
|
else if (typeof value === "function") {
|
|
5911
|
-
throw
|
|
5934
|
+
throw new MstError("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?"));
|
|
5912
5935
|
}
|
|
5913
5936
|
// no other complex values
|
|
5914
5937
|
else if (typeof value === "object") {
|
|
5915
|
-
throw
|
|
5938
|
+
throw new MstError("Invalid type definition for property '".concat(key, "', it looks like you passed an object. Try passing another model type or a types.frozen."));
|
|
5916
5939
|
}
|
|
5917
5940
|
else {
|
|
5918
|
-
throw
|
|
5941
|
+
throw new MstError("Invalid type definition for property '".concat(key, "', cannot infer a type from a value like '").concat(value, "' (").concat(typeof value, ")"));
|
|
5919
5942
|
}
|
|
5920
5943
|
return props;
|
|
5921
|
-
}, declaredProps);
|
|
5944
|
+
}, __assign({}, declaredProps));
|
|
5922
5945
|
}
|
|
5923
5946
|
/**
|
|
5924
5947
|
* @internal
|
|
@@ -6028,7 +6051,7 @@
|
|
|
6028
6051
|
this.forAllProps(function (propName, propType) {
|
|
6029
6052
|
if (propType.flags & TypeFlags.Identifier) {
|
|
6030
6053
|
if (identifierAttribute)
|
|
6031
|
-
throw
|
|
6054
|
+
throw new MstError("Cannot define property '".concat(propName, "' as object identifier, property '").concat(identifierAttribute, "' is already defined as identifier property"));
|
|
6032
6055
|
identifierAttribute = propName;
|
|
6033
6056
|
}
|
|
6034
6057
|
});
|
|
@@ -6069,15 +6092,15 @@
|
|
|
6069
6092
|
value: function (self, actions) {
|
|
6070
6093
|
// check if return is correct
|
|
6071
6094
|
if (!isPlainObject(actions))
|
|
6072
|
-
throw
|
|
6095
|
+
throw new MstError("actions initializer should return a plain object containing actions");
|
|
6073
6096
|
// bind actions to the object created
|
|
6074
6097
|
Object.keys(actions).forEach(function (name) {
|
|
6075
6098
|
// warn if preprocessor was given
|
|
6076
6099
|
if (name === PRE_PROCESS_SNAPSHOT)
|
|
6077
|
-
throw
|
|
6100
|
+
throw new MstError("Cannot define action '".concat(PRE_PROCESS_SNAPSHOT, "', it should be defined using 'type.preProcessSnapshot(fn)' instead"));
|
|
6078
6101
|
// warn if postprocessor was given
|
|
6079
6102
|
if (name === POST_PROCESS_SNAPSHOT)
|
|
6080
|
-
throw
|
|
6103
|
+
throw new MstError("Cannot define action '".concat(POST_PROCESS_SNAPSHOT, "', it should be defined using 'type.postProcessSnapshot(fn)' instead"));
|
|
6081
6104
|
var action2 = actions[name];
|
|
6082
6105
|
// apply hook composition
|
|
6083
6106
|
var baseAction = self[name];
|
|
@@ -6107,7 +6130,7 @@
|
|
|
6107
6130
|
value: function (fn) {
|
|
6108
6131
|
var _this = this;
|
|
6109
6132
|
if (typeof fn !== "function") {
|
|
6110
|
-
throw
|
|
6133
|
+
throw new MstError("You passed an ".concat(typeof fn, " to volatile state as an argument, when function is expected"));
|
|
6111
6134
|
}
|
|
6112
6135
|
var stateInitializer = function (self) {
|
|
6113
6136
|
_this.instantiateVolatileState(self, fn(self));
|
|
@@ -6123,7 +6146,7 @@
|
|
|
6123
6146
|
value: function (self, state) {
|
|
6124
6147
|
// check views return
|
|
6125
6148
|
if (!isPlainObject(state))
|
|
6126
|
-
throw
|
|
6149
|
+
throw new MstError("volatile state initializer should return a plain object containing state");
|
|
6127
6150
|
mobx.set(self, state);
|
|
6128
6151
|
}
|
|
6129
6152
|
});
|
|
@@ -6136,7 +6159,7 @@
|
|
|
6136
6159
|
var initializer = function (self) {
|
|
6137
6160
|
var _a = fn(self), actions = _a.actions, views = _a.views, state = _a.state, rest = __rest(_a, ["actions", "views", "state"]);
|
|
6138
6161
|
for (var key in rest)
|
|
6139
|
-
throw
|
|
6162
|
+
throw new MstError("The `extend` function should return an object with a subset of the fields 'actions', 'views' and 'state'. Found invalid key '".concat(key, "'"));
|
|
6140
6163
|
if (state)
|
|
6141
6164
|
_this.instantiateVolatileState(self, state);
|
|
6142
6165
|
if (views)
|
|
@@ -6168,7 +6191,7 @@
|
|
|
6168
6191
|
value: function (self, views) {
|
|
6169
6192
|
// check views return
|
|
6170
6193
|
if (!isPlainObject(views))
|
|
6171
|
-
throw
|
|
6194
|
+
throw new MstError("views initializer should return a plain object containing views");
|
|
6172
6195
|
Object.getOwnPropertyNames(views).forEach(function (key) {
|
|
6173
6196
|
var _a;
|
|
6174
6197
|
// is this a computed property?
|
|
@@ -6181,7 +6204,7 @@
|
|
|
6181
6204
|
(addHiddenWritableProp)(self, key, descriptor.value);
|
|
6182
6205
|
}
|
|
6183
6206
|
else {
|
|
6184
|
-
throw
|
|
6207
|
+
throw new MstError("A view member should either be a function or getter based property");
|
|
6185
6208
|
}
|
|
6186
6209
|
});
|
|
6187
6210
|
}
|
|
@@ -6297,11 +6320,11 @@
|
|
|
6297
6320
|
value: function (node, key) {
|
|
6298
6321
|
var _a;
|
|
6299
6322
|
if (!(key in this.properties))
|
|
6300
|
-
throw
|
|
6323
|
+
throw new MstError("Not a value property: " + key);
|
|
6301
6324
|
var adm = mobx._getAdministration(node.storedValue, key);
|
|
6302
6325
|
var childNode = (_a = adm.raw) === null || _a === void 0 ? void 0 : _a.call(adm);
|
|
6303
6326
|
if (!childNode)
|
|
6304
|
-
throw
|
|
6327
|
+
throw new MstError("Node not available for property " + key);
|
|
6305
6328
|
return childNode;
|
|
6306
6329
|
}
|
|
6307
6330
|
});
|
|
@@ -6320,7 +6343,7 @@
|
|
|
6320
6343
|
atom.reportObserved();
|
|
6321
6344
|
}
|
|
6322
6345
|
catch (e) {
|
|
6323
|
-
throw
|
|
6346
|
+
throw new MstError("".concat(name, " property is declared twice"));
|
|
6324
6347
|
}
|
|
6325
6348
|
res[name] = _this.getChildNode(node, name).snapshot;
|
|
6326
6349
|
});
|
|
@@ -6348,7 +6371,7 @@
|
|
|
6348
6371
|
writable: true,
|
|
6349
6372
|
value: function (node, subpath, patch) {
|
|
6350
6373
|
if (!(patch.op === "replace" || patch.op === "add")) {
|
|
6351
|
-
throw
|
|
6374
|
+
throw new MstError("object does not support operation ".concat(patch.op));
|
|
6352
6375
|
}
|
|
6353
6376
|
node.storedValue[subpath] = patch.value;
|
|
6354
6377
|
}
|
|
@@ -6460,7 +6483,7 @@
|
|
|
6460
6483
|
args[_i] = arguments[_i];
|
|
6461
6484
|
}
|
|
6462
6485
|
if (typeof args[0] !== "string" && args[1]) {
|
|
6463
|
-
throw
|
|
6486
|
+
throw new MstError("Model creation failed. First argument must be a string when two arguments are provided");
|
|
6464
6487
|
}
|
|
6465
6488
|
var name = typeof args[0] === "string" ? args.shift() : "AnonymousModel";
|
|
6466
6489
|
var properties = args.shift() || {};
|
|
@@ -6707,7 +6730,7 @@
|
|
|
6707
6730
|
if (value instanceof Date)
|
|
6708
6731
|
return DatePrimitive;
|
|
6709
6732
|
}
|
|
6710
|
-
throw
|
|
6733
|
+
throw new MstError("Cannot determine primitive type from value " + value);
|
|
6711
6734
|
}
|
|
6712
6735
|
/**
|
|
6713
6736
|
* Returns if a given value represents a primitive type.
|
|
@@ -7027,7 +7050,7 @@
|
|
|
7027
7050
|
value: function (parent, subpath, environment, initialValue) {
|
|
7028
7051
|
var type = this.determineType(initialValue, undefined);
|
|
7029
7052
|
if (!type)
|
|
7030
|
-
throw
|
|
7053
|
+
throw new MstError("No matching type for union " + this.describe()); // can happen in prod builds
|
|
7031
7054
|
return type.instantiate(parent, subpath, environment, initialValue);
|
|
7032
7055
|
}
|
|
7033
7056
|
});
|
|
@@ -7038,7 +7061,7 @@
|
|
|
7038
7061
|
value: function (current, newValue, parent, subpath) {
|
|
7039
7062
|
var type = this.determineType(newValue, current.getReconciliationType());
|
|
7040
7063
|
if (!type)
|
|
7041
|
-
throw
|
|
7064
|
+
throw new MstError("No matching type for union " + this.describe()); // can happen in prod builds
|
|
7042
7065
|
return type.reconcile(current, newValue, parent, subpath);
|
|
7043
7066
|
}
|
|
7044
7067
|
});
|
|
@@ -7253,7 +7276,7 @@
|
|
|
7253
7276
|
function checkOptionalPreconditions(type, defaultValueOrFunction) {
|
|
7254
7277
|
// make sure we never pass direct instances
|
|
7255
7278
|
if (typeof defaultValueOrFunction !== "function" && isStateTreeNode(defaultValueOrFunction)) {
|
|
7256
|
-
throw
|
|
7279
|
+
throw new MstError("default value cannot be an instance, pass a snapshot or a function that creates an instance/snapshot instead");
|
|
7257
7280
|
}
|
|
7258
7281
|
assertIsType(type, 1);
|
|
7259
7282
|
{
|
|
@@ -7392,10 +7415,10 @@
|
|
|
7392
7415
|
throw e;
|
|
7393
7416
|
}
|
|
7394
7417
|
if (mustSucceed && t === undefined)
|
|
7395
|
-
throw
|
|
7418
|
+
throw new MstError("Late type seems to be used too early, the definition (still) returns undefined");
|
|
7396
7419
|
if (t) {
|
|
7397
7420
|
if (!isType(t))
|
|
7398
|
-
throw
|
|
7421
|
+
throw new MstError("Failed to determine subtype, make sure types.late returns a type definition.");
|
|
7399
7422
|
this._subType = t;
|
|
7400
7423
|
}
|
|
7401
7424
|
}
|
|
@@ -7482,7 +7505,7 @@
|
|
|
7482
7505
|
// checks that the type is actually a late type
|
|
7483
7506
|
{
|
|
7484
7507
|
if (!(typeof type === "function" && type.length === 0))
|
|
7485
|
-
throw
|
|
7508
|
+
throw new MstError("Invalid late type, expected a function with zero arguments that returns a type, got: " +
|
|
7486
7509
|
type);
|
|
7487
7510
|
}
|
|
7488
7511
|
return new Late(name, type);
|
|
@@ -7765,15 +7788,15 @@
|
|
|
7765
7788
|
else if (isStateTreeNode(value)) {
|
|
7766
7789
|
var targetNode = getStateTreeNode(value);
|
|
7767
7790
|
if (!targetNode.identifierAttribute)
|
|
7768
|
-
throw
|
|
7791
|
+
throw new MstError("Can only store references with a defined identifier attribute.");
|
|
7769
7792
|
var id = targetNode.unnormalizedIdentifier;
|
|
7770
7793
|
if (id === null || id === undefined) {
|
|
7771
|
-
throw
|
|
7794
|
+
throw new MstError("Can only store references to tree nodes with a defined identifier.");
|
|
7772
7795
|
}
|
|
7773
7796
|
this.identifier = id;
|
|
7774
7797
|
}
|
|
7775
7798
|
else {
|
|
7776
|
-
throw
|
|
7799
|
+
throw new MstError("Can only store references to tree nodes or identifiers, got: '".concat(value, "'"));
|
|
7777
7800
|
}
|
|
7778
7801
|
}
|
|
7779
7802
|
Object.defineProperty(StoredReference.prototype, "updateResolvedReference", {
|
|
@@ -8155,7 +8178,7 @@
|
|
|
8155
8178
|
{
|
|
8156
8179
|
if (arguments.length === 2 && typeof arguments[1] === "string") {
|
|
8157
8180
|
// istanbul ignore next
|
|
8158
|
-
throw
|
|
8181
|
+
throw new MstError("References with base path are no longer supported. Please remove the base path.");
|
|
8159
8182
|
}
|
|
8160
8183
|
}
|
|
8161
8184
|
var getSetOptions = options ? options : undefined;
|
|
@@ -8165,7 +8188,7 @@
|
|
|
8165
8188
|
if (getSetOptions && (getSetOptions.get || getSetOptions.set)) {
|
|
8166
8189
|
{
|
|
8167
8190
|
if (!getSetOptions.get || !getSetOptions.set) {
|
|
8168
|
-
throw
|
|
8191
|
+
throw new MstError("reference options must either contain both a 'get' and a 'set' method or none of them");
|
|
8169
8192
|
}
|
|
8170
8193
|
}
|
|
8171
8194
|
return new CustomReferenceType(subType, {
|
|
@@ -8243,7 +8266,7 @@
|
|
|
8243
8266
|
writable: true,
|
|
8244
8267
|
value: function (parent, subpath, environment, initialValue) {
|
|
8245
8268
|
if (!parent || !(parent.type instanceof ModelType))
|
|
8246
|
-
throw
|
|
8269
|
+
throw new MstError("Identifier types can only be instantiated as direct child of a model type");
|
|
8247
8270
|
return createScalarNode(this, parent, subpath, environment, initialValue);
|
|
8248
8271
|
}
|
|
8249
8272
|
});
|
|
@@ -8254,7 +8277,7 @@
|
|
|
8254
8277
|
value: function (current, newValue, parent, subpath) {
|
|
8255
8278
|
// we don't consider detaching here since identifier are scalar nodes, and scalar nodes cannot be detached
|
|
8256
8279
|
if (current.storedValue !== newValue)
|
|
8257
|
-
throw
|
|
8280
|
+
throw new MstError("Tried to change identifier from '".concat(current.storedValue, "' to '").concat(newValue, "'. Changing identifiers is not allowed."));
|
|
8258
8281
|
current.setParent(parent, subpath);
|
|
8259
8282
|
return current;
|
|
8260
8283
|
}
|