mobx-state-tree 5.4.2-pre.1 → 5.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/action.d.ts +2 -2
- package/dist/core/flow.d.ts +1 -1
- package/dist/core/mst-operations.d.ts +1 -1
- package/dist/core/node/Hook.d.ts +1 -1
- package/dist/core/node/livelinessChecking.d.ts +2 -2
- package/dist/core/node/node-utils.d.ts +1 -1
- package/dist/core/type/type-checker.d.ts +2 -2
- package/dist/core/type/type.d.ts +8 -8
- package/dist/mobx-state-tree.js +118 -122
- package/dist/mobx-state-tree.min.js +16 -1
- package/dist/mobx-state-tree.module.js +118 -122
- package/dist/mobx-state-tree.umd.js +120 -124
- package/dist/mobx-state-tree.umd.min.js +16 -1
- package/dist/types/complex-types/model.d.ts +25 -20
- package/dist/types/utility-types/enumeration.d.ts +3 -3
- package/dist/types/utility-types/identifier.d.ts +1 -1
- package/dist/types/utility-types/optional.d.ts +3 -3
- package/dist/types/utility-types/reference.d.ts +4 -4
- package/dist/types/utility-types/snapshotProcessor.d.ts +1 -1
- package/dist/types/utility-types/union.d.ts +37 -7
- package/dist/utils.d.ts +1 -1
- package/package.json +14 -14
|
@@ -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
|
-
}
|
|
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 */
|
|
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 (
|
|
112
|
+
while (_) try {
|
|
113
113
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
114
114
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
115
115
|
switch (op[0]) {
|
|
@@ -160,20 +160,12 @@
|
|
|
160
160
|
return ar;
|
|
161
161
|
}
|
|
162
162
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
}
|
|
170
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
174
|
-
var e = new Error(message);
|
|
175
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
176
|
-
};
|
|
163
|
+
/** @deprecated */
|
|
164
|
+
function __spread() {
|
|
165
|
+
for (var ar = [], i = 0; i < arguments.length; i++)
|
|
166
|
+
ar = ar.concat(__read(arguments[i]));
|
|
167
|
+
return ar;
|
|
168
|
+
}
|
|
177
169
|
|
|
178
170
|
/**
|
|
179
171
|
* Returns the _actual_ type of the given tree node. (Or throws)
|
|
@@ -471,7 +463,7 @@
|
|
|
471
463
|
return parent.storedValue;
|
|
472
464
|
parent = parent.parent;
|
|
473
465
|
}
|
|
474
|
-
throw fail("Failed to find the parent of "
|
|
466
|
+
throw fail("Failed to find the parent of " + getStateTreeNode(target) + " at depth " + depth);
|
|
475
467
|
}
|
|
476
468
|
/**
|
|
477
469
|
* Given a model instance, returns `true` if the object has a parent of given type, that is, is part of another object, map or array
|
|
@@ -509,7 +501,7 @@
|
|
|
509
501
|
return parent.storedValue;
|
|
510
502
|
parent = parent.parent;
|
|
511
503
|
}
|
|
512
|
-
throw fail("Failed to find the parent of "
|
|
504
|
+
throw fail("Failed to find the parent of " + getStateTreeNode(target) + " of a given type");
|
|
513
505
|
}
|
|
514
506
|
/**
|
|
515
507
|
* Given an object in a model tree, returns the root object of that tree.
|
|
@@ -877,14 +869,18 @@
|
|
|
877
869
|
reflected.volatile.push(key);
|
|
878
870
|
return;
|
|
879
871
|
}
|
|
880
|
-
if (descriptor.value.
|
|
881
|
-
reflected.actions.push(key);
|
|
882
|
-
if (descriptor.value._isFlowAction === true)
|
|
872
|
+
if (descriptor.value._isFlowAction === true) {
|
|
883
873
|
reflected.flowActions.push(key);
|
|
884
|
-
|
|
874
|
+
}
|
|
875
|
+
if (descriptor.value._isMSTAction === true) {
|
|
876
|
+
reflected.actions.push(key);
|
|
877
|
+
}
|
|
878
|
+
else if (mobx.isObservableProp(target, key)) {
|
|
885
879
|
reflected.volatile.push(key);
|
|
886
|
-
|
|
880
|
+
}
|
|
881
|
+
else {
|
|
887
882
|
reflected.views.push(key);
|
|
883
|
+
}
|
|
888
884
|
});
|
|
889
885
|
return reflected;
|
|
890
886
|
}
|
|
@@ -1364,7 +1360,7 @@
|
|
|
1364
1360
|
writable: true,
|
|
1365
1361
|
value: function () {
|
|
1366
1362
|
var path = (this.isAlive ? this.path : this.pathUponDeath) || "<root>";
|
|
1367
|
-
return
|
|
1363
|
+
return this.type.name + "@" + path + (this.isAlive ? "" : " [dead]");
|
|
1368
1364
|
}
|
|
1369
1365
|
});
|
|
1370
1366
|
Object.defineProperty(ScalarNode.prototype, "die", {
|
|
@@ -1510,7 +1506,7 @@
|
|
|
1510
1506
|
enumerable: true,
|
|
1511
1507
|
configurable: true,
|
|
1512
1508
|
writable: true,
|
|
1513
|
-
value: 0 /*
|
|
1509
|
+
value: 0 /* UNINITIALIZED */
|
|
1514
1510
|
});
|
|
1515
1511
|
Object.defineProperty(_this, "_childNodes", {
|
|
1516
1512
|
enumerable: true,
|
|
@@ -1577,7 +1573,7 @@
|
|
|
1577
1573
|
}
|
|
1578
1574
|
}
|
|
1579
1575
|
if (typeof id !== "string" && typeof id !== "number") {
|
|
1580
|
-
throw fail("Instance identifier '"
|
|
1576
|
+
throw fail("Instance identifier '" + _this.identifierAttribute + "' for type '" + _this.type.name + "' must be a string or a number");
|
|
1581
1577
|
}
|
|
1582
1578
|
// normalize internal identifier to string
|
|
1583
1579
|
_this.identifier = normalizeIdentifier(id);
|
|
@@ -1615,7 +1611,7 @@
|
|
|
1615
1611
|
writable: true,
|
|
1616
1612
|
value: function (fireHooks) {
|
|
1617
1613
|
if (fireHooks === void 0) { fireHooks = true; }
|
|
1618
|
-
if (this._observableInstanceState === 0 /*
|
|
1614
|
+
if (this._observableInstanceState === 0 /* UNINITIALIZED */) {
|
|
1619
1615
|
this.createObservableInstance(fireHooks);
|
|
1620
1616
|
}
|
|
1621
1617
|
}
|
|
@@ -1633,7 +1629,7 @@
|
|
|
1633
1629
|
throw fail("assertion failed: the creation of the observable instance must be done on the initializing phase");
|
|
1634
1630
|
}
|
|
1635
1631
|
}
|
|
1636
|
-
this._observableInstanceState = 1 /*
|
|
1632
|
+
this._observableInstanceState = 1 /* CREATING */;
|
|
1637
1633
|
// make sure the parent chain is created as well
|
|
1638
1634
|
// array with parent chain from parent to child
|
|
1639
1635
|
var parentChain = [];
|
|
@@ -1643,7 +1639,7 @@
|
|
|
1643
1639
|
// this is done to avoid traversing the whole tree to the root when using
|
|
1644
1640
|
// the same reference again
|
|
1645
1641
|
while (parent &&
|
|
1646
|
-
parent._observableInstanceState === 0 /*
|
|
1642
|
+
parent._observableInstanceState === 0 /* UNINITIALIZED */) {
|
|
1647
1643
|
parentChain.unshift(parent);
|
|
1648
1644
|
parent = parent.parent;
|
|
1649
1645
|
}
|
|
@@ -1677,7 +1673,7 @@
|
|
|
1677
1673
|
finally {
|
|
1678
1674
|
this._isRunningAction = false;
|
|
1679
1675
|
}
|
|
1680
|
-
this._observableInstanceState = 2 /*
|
|
1676
|
+
this._observableInstanceState = 2 /* CREATED */;
|
|
1681
1677
|
this._snapshotComputed.trackAndCompute();
|
|
1682
1678
|
if (this.isRoot)
|
|
1683
1679
|
this._addSnapshotReaction();
|
|
@@ -1760,10 +1756,10 @@
|
|
|
1760
1756
|
throw fail("assertion failed: new parent expected");
|
|
1761
1757
|
}
|
|
1762
1758
|
if (this.parent && parentChanged) {
|
|
1763
|
-
throw fail("A node cannot exists twice in the state tree. Failed to add "
|
|
1759
|
+
throw fail("A node cannot exists twice in the state tree. Failed to add " + this + " to path '" + newParent.path + "/" + subpath + "'.");
|
|
1764
1760
|
}
|
|
1765
1761
|
if (!this.parent && newParent.root === this) {
|
|
1766
|
-
throw fail("A state tree is not allowed to contain itself. Cannot assign "
|
|
1762
|
+
throw fail("A state tree is not allowed to contain itself. Cannot assign " + this + " to path '" + newParent.path + "/" + subpath + "'");
|
|
1767
1763
|
}
|
|
1768
1764
|
if (!this.parent && !!this.environment && this.environment !== newParent.root.environment) {
|
|
1769
1765
|
throw fail("A state tree cannot be made part of another state tree as long as their environments are different.");
|
|
@@ -1822,7 +1818,7 @@
|
|
|
1822
1818
|
value: function () {
|
|
1823
1819
|
if (!this.isAlive)
|
|
1824
1820
|
return this._snapshotUponDeath;
|
|
1825
|
-
return this._observableInstanceState === 2 /*
|
|
1821
|
+
return this._observableInstanceState === 2 /* CREATED */
|
|
1826
1822
|
? this._getActualSnapshot()
|
|
1827
1823
|
: this._getCachedInitialSnapshot();
|
|
1828
1824
|
}
|
|
@@ -1895,9 +1891,9 @@
|
|
|
1895
1891
|
if (actionContext && actionContext.name != null) {
|
|
1896
1892
|
// try to use the context, and if it not available use the node one
|
|
1897
1893
|
var actionPath = (actionContext && actionContext.context && getPath(actionContext.context)) || escapedPath;
|
|
1898
|
-
actionFullPath =
|
|
1894
|
+
actionFullPath = actionPath + "." + actionContext.name + "()";
|
|
1899
1895
|
}
|
|
1900
|
-
return "You are trying to read or write to an object that is no longer part of a state tree. (Object type: '"
|
|
1896
|
+
return "You are trying to read or write to an object that is no longer part of a state tree. (Object type: '" + this.type.name + "', Path upon death: '" + escapedPath + "', Subpath: '" + subpath + "', Action: '" + actionFullPath + "'). Either detach nodes first, or don't use objects after removing / replacing them in the tree.";
|
|
1901
1897
|
}
|
|
1902
1898
|
});
|
|
1903
1899
|
Object.defineProperty(ObjectNode.prototype, "getChildNode", {
|
|
@@ -1910,7 +1906,7 @@
|
|
|
1910
1906
|
});
|
|
1911
1907
|
this._autoUnbox = false;
|
|
1912
1908
|
try {
|
|
1913
|
-
return this._observableInstanceState === 2 /*
|
|
1909
|
+
return this._observableInstanceState === 2 /* CREATED */
|
|
1914
1910
|
? this.type.getChildNode(this, subpath)
|
|
1915
1911
|
: this._childNodes[subpath];
|
|
1916
1912
|
}
|
|
@@ -1927,7 +1923,7 @@
|
|
|
1927
1923
|
this.assertAlive(EMPTY_OBJECT);
|
|
1928
1924
|
this._autoUnbox = false;
|
|
1929
1925
|
try {
|
|
1930
|
-
return this._observableInstanceState === 2 /*
|
|
1926
|
+
return this._observableInstanceState === 2 /* CREATED */
|
|
1931
1927
|
? this.type.getChildren(this)
|
|
1932
1928
|
: convertChildNodesToArray(this._childNodes);
|
|
1933
1929
|
}
|
|
@@ -1958,7 +1954,7 @@
|
|
|
1958
1954
|
value: function (context) {
|
|
1959
1955
|
this.assertAlive(context);
|
|
1960
1956
|
if (!this.isRunningAction() && this.isProtected) {
|
|
1961
|
-
throw fail("Cannot modify '"
|
|
1957
|
+
throw fail("Cannot modify '" + this + "', the object is protected and can only be modified by using an action.");
|
|
1962
1958
|
}
|
|
1963
1959
|
}
|
|
1964
1960
|
});
|
|
@@ -1990,8 +1986,8 @@
|
|
|
1990
1986
|
writable: true,
|
|
1991
1987
|
value: function () {
|
|
1992
1988
|
var path = (this.isAlive ? this.path : this.pathUponDeath) || "<root>";
|
|
1993
|
-
var identifier = this.identifier ? "(id: "
|
|
1994
|
-
return
|
|
1989
|
+
var identifier = this.identifier ? "(id: " + this.identifier + ")" : "";
|
|
1990
|
+
return this.type.name + "@" + path + identifier + (this.isAlive ? "" : " [dead]");
|
|
1995
1991
|
}
|
|
1996
1992
|
});
|
|
1997
1993
|
Object.defineProperty(ObjectNode.prototype, "finalizeCreation", {
|
|
@@ -2073,7 +2069,7 @@
|
|
|
2073
2069
|
configurable: true,
|
|
2074
2070
|
writable: true,
|
|
2075
2071
|
value: function () {
|
|
2076
|
-
if (this._observableInstanceState === 0 /*
|
|
2072
|
+
if (this._observableInstanceState === 0 /* UNINITIALIZED */) {
|
|
2077
2073
|
return;
|
|
2078
2074
|
}
|
|
2079
2075
|
this.getChildren().forEach(function (node) {
|
|
@@ -2082,8 +2078,8 @@
|
|
|
2082
2078
|
// beforeDestroy should run before the disposers since else we could end up in a situation where
|
|
2083
2079
|
// a disposer added with addDisposer at this stage (beforeDestroy) is actually never released
|
|
2084
2080
|
this.baseAboutToDie();
|
|
2085
|
-
this._internalEventsEmit("dispose" /*
|
|
2086
|
-
this._internalEventsClear("dispose" /*
|
|
2081
|
+
this._internalEventsEmit("dispose" /* Dispose */);
|
|
2082
|
+
this._internalEventsClear("dispose" /* Dispose */);
|
|
2087
2083
|
}
|
|
2088
2084
|
});
|
|
2089
2085
|
Object.defineProperty(ObjectNode.prototype, "finalizeDeath", {
|
|
@@ -2109,7 +2105,7 @@
|
|
|
2109
2105
|
writable: true,
|
|
2110
2106
|
value: function (onChange) {
|
|
2111
2107
|
this._addSnapshotReaction();
|
|
2112
|
-
return this._internalEventsRegister("snapshot" /*
|
|
2108
|
+
return this._internalEventsRegister("snapshot" /* Snapshot */, onChange);
|
|
2113
2109
|
}
|
|
2114
2110
|
});
|
|
2115
2111
|
Object.defineProperty(ObjectNode.prototype, "emitSnapshot", {
|
|
@@ -2117,7 +2113,7 @@
|
|
|
2117
2113
|
configurable: true,
|
|
2118
2114
|
writable: true,
|
|
2119
2115
|
value: function (snapshot) {
|
|
2120
|
-
this._internalEventsEmit("snapshot" /*
|
|
2116
|
+
this._internalEventsEmit("snapshot" /* Snapshot */, snapshot);
|
|
2121
2117
|
}
|
|
2122
2118
|
});
|
|
2123
2119
|
Object.defineProperty(ObjectNode.prototype, "onPatch", {
|
|
@@ -2125,7 +2121,7 @@
|
|
|
2125
2121
|
configurable: true,
|
|
2126
2122
|
writable: true,
|
|
2127
2123
|
value: function (handler) {
|
|
2128
|
-
return this._internalEventsRegister("patch" /*
|
|
2124
|
+
return this._internalEventsRegister("patch" /* Patch */, handler);
|
|
2129
2125
|
}
|
|
2130
2126
|
});
|
|
2131
2127
|
Object.defineProperty(ObjectNode.prototype, "emitPatch", {
|
|
@@ -2133,12 +2129,12 @@
|
|
|
2133
2129
|
configurable: true,
|
|
2134
2130
|
writable: true,
|
|
2135
2131
|
value: function (basePatch, source) {
|
|
2136
|
-
if (this._internalEventsHasSubscribers("patch" /*
|
|
2132
|
+
if (this._internalEventsHasSubscribers("patch" /* Patch */)) {
|
|
2137
2133
|
var localizedPatch = extend({}, basePatch, {
|
|
2138
2134
|
path: source.path.substr(this.path.length) + "/" + basePatch.path // calculate the relative path of the patch
|
|
2139
2135
|
});
|
|
2140
2136
|
var _a = __read(splitPatch(localizedPatch), 2), patch = _a[0], reversePatch = _a[1];
|
|
2141
|
-
this._internalEventsEmit("patch" /*
|
|
2137
|
+
this._internalEventsEmit("patch" /* Patch */, patch, reversePatch);
|
|
2142
2138
|
}
|
|
2143
2139
|
if (this.parent)
|
|
2144
2140
|
this.parent.emitPatch(basePatch, source);
|
|
@@ -2149,7 +2145,7 @@
|
|
|
2149
2145
|
configurable: true,
|
|
2150
2146
|
writable: true,
|
|
2151
2147
|
value: function (disposer) {
|
|
2152
|
-
return this._internalEventsHas("dispose" /*
|
|
2148
|
+
return this._internalEventsHas("dispose" /* Dispose */, disposer);
|
|
2153
2149
|
}
|
|
2154
2150
|
});
|
|
2155
2151
|
Object.defineProperty(ObjectNode.prototype, "addDisposer", {
|
|
@@ -2158,7 +2154,7 @@
|
|
|
2158
2154
|
writable: true,
|
|
2159
2155
|
value: function (disposer) {
|
|
2160
2156
|
if (!this.hasDisposer(disposer)) {
|
|
2161
|
-
this._internalEventsRegister("dispose" /*
|
|
2157
|
+
this._internalEventsRegister("dispose" /* Dispose */, disposer, true);
|
|
2162
2158
|
return;
|
|
2163
2159
|
}
|
|
2164
2160
|
throw fail("cannot add a disposer when it is already registered for execution");
|
|
@@ -2169,10 +2165,10 @@
|
|
|
2169
2165
|
configurable: true,
|
|
2170
2166
|
writable: true,
|
|
2171
2167
|
value: function (disposer) {
|
|
2172
|
-
if (!this._internalEventsHas("dispose" /*
|
|
2168
|
+
if (!this._internalEventsHas("dispose" /* Dispose */, disposer)) {
|
|
2173
2169
|
throw fail("cannot remove a disposer which was never registered for execution");
|
|
2174
2170
|
}
|
|
2175
|
-
this._internalEventsUnregister("dispose" /*
|
|
2171
|
+
this._internalEventsUnregister("dispose" /* Dispose */, disposer);
|
|
2176
2172
|
}
|
|
2177
2173
|
});
|
|
2178
2174
|
Object.defineProperty(ObjectNode.prototype, "removeMiddleware", {
|
|
@@ -2280,7 +2276,7 @@
|
|
|
2280
2276
|
args[_i - 1] = arguments[_i];
|
|
2281
2277
|
}
|
|
2282
2278
|
if (this._internalEvents) {
|
|
2283
|
-
(_a = this._internalEvents).emit.apply(_a,
|
|
2279
|
+
(_a = this._internalEvents).emit.apply(_a, __spread([event], args));
|
|
2284
2280
|
}
|
|
2285
2281
|
}
|
|
2286
2282
|
});
|
|
@@ -2923,11 +2919,11 @@
|
|
|
2923
2919
|
// We should not serialize MST nodes, even if we can, because we don't know if the receiving party can handle a raw snapshot instead of an
|
|
2924
2920
|
// MST type instance. So if one wants to serialize a MST node that was pass in, either explitly pass: 1: an id, 2: a (relative) path, 3: a snapshot
|
|
2925
2921
|
if (isStateTreeNode(arg))
|
|
2926
|
-
return serializeTheUnserializable("[MSTNode: "
|
|
2922
|
+
return serializeTheUnserializable("[MSTNode: " + getType(arg).name + "]");
|
|
2927
2923
|
if (typeof arg === "function")
|
|
2928
2924
|
return serializeTheUnserializable("[function]");
|
|
2929
2925
|
if (typeof arg === "object" && !isPlainObject(arg) && !isArray(arg))
|
|
2930
|
-
return serializeTheUnserializable("[object "
|
|
2926
|
+
return serializeTheUnserializable("[object " + ((arg && arg.constructor && arg.constructor.name) || "Complex Object") + "]");
|
|
2931
2927
|
try {
|
|
2932
2928
|
// Check if serializable, cycle free etc...
|
|
2933
2929
|
// MWE: there must be a better way....
|
|
@@ -2968,7 +2964,7 @@
|
|
|
2968
2964
|
function baseApplyAction(target, action) {
|
|
2969
2965
|
var resolvedTarget = tryResolve(target, action.path || "");
|
|
2970
2966
|
if (!resolvedTarget)
|
|
2971
|
-
throw fail("Invalid action path: "
|
|
2967
|
+
throw fail("Invalid action path: " + (action.path || ""));
|
|
2972
2968
|
var node = getStateTreeNode(resolvedTarget);
|
|
2973
2969
|
// Reserved functions
|
|
2974
2970
|
if (action.name === "@APPLY_PATCHES") {
|
|
@@ -2978,7 +2974,7 @@
|
|
|
2978
2974
|
return applySnapshot.call(null, resolvedTarget, action.args[0]);
|
|
2979
2975
|
}
|
|
2980
2976
|
if (!(typeof resolvedTarget[action.name] === "function"))
|
|
2981
|
-
throw fail("Action '"
|
|
2977
|
+
throw fail("Action '" + action.name + "' does not exist in '" + node.path + "'");
|
|
2982
2978
|
return resolvedTarget[action.name].apply(resolvedTarget, action.args ? action.args.map(function (v) { return deserializeArgument(node, v); }) : []);
|
|
2983
2979
|
}
|
|
2984
2980
|
/**
|
|
@@ -3183,7 +3179,7 @@
|
|
|
3183
3179
|
tree: getRoot(target),
|
|
3184
3180
|
rootId: parentContext ? parentContext.rootId : id,
|
|
3185
3181
|
parentId: parentContext ? parentContext.id : 0,
|
|
3186
|
-
allParentIds: parentContext ?
|
|
3182
|
+
allParentIds: parentContext ? __spread(parentContext.allParentIds, [parentContext.id]) : [],
|
|
3187
3183
|
parentEvent: parentContext,
|
|
3188
3184
|
parentActionEvent: parentActionContext
|
|
3189
3185
|
}, fn);
|
|
@@ -3339,11 +3335,11 @@
|
|
|
3339
3335
|
{
|
|
3340
3336
|
if (!nextInvoked && !abortInvoked) {
|
|
3341
3337
|
var node2 = getStateTreeNode(call.tree);
|
|
3342
|
-
throw fail("Neither the next() nor the abort() callback within the middleware "
|
|
3338
|
+
throw fail("Neither the next() nor the abort() callback within the middleware " + handler.name + " for the action: \"" + call.name + "\" on the node: " + node2.type.name + " was invoked.");
|
|
3343
3339
|
}
|
|
3344
3340
|
else if (nextInvoked && abortInvoked) {
|
|
3345
3341
|
var node2 = getStateTreeNode(call.tree);
|
|
3346
|
-
throw fail("The next() and abort() callback within the middleware "
|
|
3342
|
+
throw fail("The next() and abort() callback within the middleware " + handler.name + " for the action: \"" + call.name + "\" on the node: " + node2.type.name + " were invoked.");
|
|
3347
3343
|
}
|
|
3348
3344
|
}
|
|
3349
3345
|
return result;
|
|
@@ -3393,7 +3389,7 @@
|
|
|
3393
3389
|
}
|
|
3394
3390
|
catch (e) {
|
|
3395
3391
|
// istanbul ignore next
|
|
3396
|
-
return "<Unserializable: "
|
|
3392
|
+
return "<Unserializable: " + e + ">";
|
|
3397
3393
|
}
|
|
3398
3394
|
}
|
|
3399
3395
|
/**
|
|
@@ -3402,15 +3398,15 @@
|
|
|
3402
3398
|
*/
|
|
3403
3399
|
function prettyPrintValue(value) {
|
|
3404
3400
|
return typeof value === "function"
|
|
3405
|
-
? "<function"
|
|
3401
|
+
? "<function" + (value.name ? " " + value.name : "") + ">"
|
|
3406
3402
|
: isStateTreeNode(value)
|
|
3407
|
-
? "<"
|
|
3408
|
-
: "`"
|
|
3403
|
+
? "<" + value + ">"
|
|
3404
|
+
: "`" + safeStringify(value) + "`";
|
|
3409
3405
|
}
|
|
3410
3406
|
function shortenPrintValue(valueInString) {
|
|
3411
3407
|
return valueInString.length < 280
|
|
3412
3408
|
? valueInString
|
|
3413
|
-
:
|
|
3409
|
+
: valueInString.substring(0, 272) + "......" + valueInString.substring(valueInString.length - 8);
|
|
3414
3410
|
}
|
|
3415
3411
|
function toErrorString(error) {
|
|
3416
3412
|
var value = error.value;
|
|
@@ -3422,19 +3418,19 @@
|
|
|
3422
3418
|
})
|
|
3423
3419
|
.filter(function (path) { return path.length > 0; })
|
|
3424
3420
|
.join("/");
|
|
3425
|
-
var pathPrefix = fullPath.length > 0 ? "at path \"/"
|
|
3421
|
+
var pathPrefix = fullPath.length > 0 ? "at path \"/" + fullPath + "\" " : "";
|
|
3426
3422
|
var currentTypename = isStateTreeNode(value)
|
|
3427
|
-
? "value of type "
|
|
3423
|
+
? "value of type " + getStateTreeNode(value).type.name + ":"
|
|
3428
3424
|
: isPrimitive(value)
|
|
3429
3425
|
? "value"
|
|
3430
3426
|
: "snapshot";
|
|
3431
3427
|
var isSnapshotCompatible = type && isStateTreeNode(value) && type.is(getStateTreeNode(value).snapshot);
|
|
3432
|
-
return (""
|
|
3433
|
-
(error.message ? " ("
|
|
3428
|
+
return ("" + pathPrefix + currentTypename + " " + prettyPrintValue(value) + " is not assignable " + (type ? "to type: `" + type.name + "`" : "") +
|
|
3429
|
+
(error.message ? " (" + error.message + ")" : "") +
|
|
3434
3430
|
(type
|
|
3435
3431
|
? isPrimitiveType(type) || isPrimitive(value)
|
|
3436
3432
|
? "."
|
|
3437
|
-
: ", expected an instance of `"
|
|
3433
|
+
: ", expected an instance of `" + type.name + "` or a snapshot like `" + type.describe() + "` instead." +
|
|
3438
3434
|
(isSnapshotCompatible
|
|
3439
3435
|
? " (Note that a snapshot of the provided value is compatible with the targeted type)"
|
|
3440
3436
|
: "")
|
|
@@ -3497,7 +3493,7 @@
|
|
|
3497
3493
|
if (errors.length === 0) {
|
|
3498
3494
|
return undefined;
|
|
3499
3495
|
}
|
|
3500
|
-
return ("Error while converting "
|
|
3496
|
+
return ("Error while converting " + shortenPrintValue(prettyPrintValue(value)) + " to `" + type.name + "`:\n\n " + errors.map(toErrorString).join("\n "));
|
|
3501
3497
|
}
|
|
3502
3498
|
|
|
3503
3499
|
var identifierCacheId = 0;
|
|
@@ -3545,7 +3541,7 @@
|
|
|
3545
3541
|
writable: true,
|
|
3546
3542
|
value: function (identifier) {
|
|
3547
3543
|
var modificationId = this.lastCacheModificationPerId.get(identifier) || 0;
|
|
3548
|
-
return
|
|
3544
|
+
return this.cacheId + "-" + modificationId;
|
|
3549
3545
|
}
|
|
3550
3546
|
});
|
|
3551
3547
|
Object.defineProperty(IdentifierCache.prototype, "addNodeToCache", {
|
|
@@ -3660,9 +3656,9 @@
|
|
|
3660
3656
|
case 1:
|
|
3661
3657
|
return matches[0];
|
|
3662
3658
|
default:
|
|
3663
|
-
throw fail("Cannot resolve a reference to type '"
|
|
3659
|
+
throw fail("Cannot resolve a reference to type '" + type.name + "' with id: '" + identifier + "' unambigously, there are multiple candidates: " + matches
|
|
3664
3660
|
.map(function (n) { return n.path; })
|
|
3665
|
-
.join(", "))
|
|
3661
|
+
.join(", "));
|
|
3666
3662
|
}
|
|
3667
3663
|
}
|
|
3668
3664
|
});
|
|
@@ -3678,7 +3674,7 @@
|
|
|
3678
3674
|
if (existingNode) {
|
|
3679
3675
|
if (existingNode.parent) {
|
|
3680
3676
|
// istanbul ignore next
|
|
3681
|
-
throw fail("Cannot add an object to a state tree if it is already part of the same or another state tree. Tried to assign an object to '"
|
|
3677
|
+
throw fail("Cannot add an object to a state tree if it is already part of the same or another state tree. Tried to assign an object to '" + (parent ? parent.path : "") + "/" + subpath + "', but it lives already at '" + existingNode.path + "'");
|
|
3682
3678
|
}
|
|
3683
3679
|
if (parent) {
|
|
3684
3680
|
existingNode.setParent(parent, subpath);
|
|
@@ -3741,7 +3737,7 @@
|
|
|
3741
3737
|
function getStateTreeNode(value) {
|
|
3742
3738
|
if (!isStateTreeNode(value)) {
|
|
3743
3739
|
// istanbul ignore next
|
|
3744
|
-
throw fail("Value "
|
|
3740
|
+
throw fail("Value " + value + " is no MST Node");
|
|
3745
3741
|
}
|
|
3746
3742
|
return value.$treenode;
|
|
3747
3743
|
}
|
|
@@ -3767,7 +3763,7 @@
|
|
|
3767
3763
|
function getRelativePathBetweenNodes(base, target) {
|
|
3768
3764
|
// PRE condition target is (a child of) base!
|
|
3769
3765
|
if (base.root !== target.root) {
|
|
3770
|
-
throw fail("Cannot calculate relative path: objects '"
|
|
3766
|
+
throw fail("Cannot calculate relative path: objects '" + base + "' and '" + target + "' are not part of the same object tree");
|
|
3771
3767
|
}
|
|
3772
3768
|
var baseParts = splitJsonPath(base.path);
|
|
3773
3769
|
var targetParts = splitJsonPath(target.path);
|
|
@@ -3824,7 +3820,7 @@
|
|
|
3824
3820
|
}
|
|
3825
3821
|
}
|
|
3826
3822
|
}
|
|
3827
|
-
throw fail("Could not resolve '"
|
|
3823
|
+
throw fail("Could not resolve '" + part + "' in path '" + (joinJsonPath(pathParts.slice(0, i)) || "/") + "' while resolving '" + joinJsonPath(pathParts) + "'");
|
|
3828
3824
|
}
|
|
3829
3825
|
}
|
|
3830
3826
|
catch (e) {
|
|
@@ -4140,7 +4136,7 @@
|
|
|
4140
4136
|
}
|
|
4141
4137
|
// make a copy just in case it changes
|
|
4142
4138
|
var handlers = this.handlers.slice();
|
|
4143
|
-
handlers.forEach(function (f) { return f.apply(void 0,
|
|
4139
|
+
handlers.forEach(function (f) { return f.apply(void 0, __spread(args)); });
|
|
4144
4140
|
}
|
|
4145
4141
|
});
|
|
4146
4142
|
return EventHandler;
|
|
@@ -4233,7 +4229,7 @@
|
|
|
4233
4229
|
}
|
|
4234
4230
|
var handler = this.eventHandlers && this.eventHandlers[event];
|
|
4235
4231
|
if (handler) {
|
|
4236
|
-
(_a = handler).emit.apply(_a,
|
|
4232
|
+
(_a = handler).emit.apply(_a, __spread(args));
|
|
4237
4233
|
}
|
|
4238
4234
|
}
|
|
4239
4235
|
});
|
|
@@ -4275,7 +4271,7 @@
|
|
|
4275
4271
|
* @hidden
|
|
4276
4272
|
*/
|
|
4277
4273
|
function warnError(msg) {
|
|
4278
|
-
console.warn(new Error("[mobx-state-tree] "
|
|
4274
|
+
console.warn(new Error("[mobx-state-tree] " + msg));
|
|
4279
4275
|
}
|
|
4280
4276
|
/**
|
|
4281
4277
|
* @internal
|
|
@@ -4285,7 +4281,7 @@
|
|
|
4285
4281
|
{
|
|
4286
4282
|
if (!fn(value)) {
|
|
4287
4283
|
// istanbul ignore next
|
|
4288
|
-
throw fail("expected "
|
|
4284
|
+
throw fail("expected " + typeName + " as argument " + asArray(argNumber).join(" or ") + ", got " + value + " instead");
|
|
4289
4285
|
}
|
|
4290
4286
|
}
|
|
4291
4287
|
}
|
|
@@ -4303,10 +4299,10 @@
|
|
|
4303
4299
|
function assertIsNumber(value, argNumber, min, max) {
|
|
4304
4300
|
assertArg(value, function (n) { return typeof n === "number"; }, "number", argNumber);
|
|
4305
4301
|
if (min !== undefined) {
|
|
4306
|
-
assertArg(value, function (n) { return n >= min; }, "number greater than "
|
|
4302
|
+
assertArg(value, function (n) { return n >= min; }, "number greater than " + min, argNumber);
|
|
4307
4303
|
}
|
|
4308
4304
|
if (max !== undefined) {
|
|
4309
|
-
assertArg(value, function (n) { return n <= max; }, "number lesser than "
|
|
4305
|
+
assertArg(value, function (n) { return n <= max; }, "number lesser than " + max, argNumber);
|
|
4310
4306
|
}
|
|
4311
4307
|
}
|
|
4312
4308
|
/**
|
|
@@ -4385,7 +4381,7 @@
|
|
|
4385
4381
|
}
|
|
4386
4382
|
return __generator(this, function (_a) {
|
|
4387
4383
|
switch (_a.label) {
|
|
4388
|
-
case 0: return [4 /*yield*/, p.apply(void 0,
|
|
4384
|
+
case 0: return [4 /*yield*/, p.apply(void 0, __spread(args))];
|
|
4389
4385
|
case 1: return [2 /*return*/, (_a.sent())];
|
|
4390
4386
|
}
|
|
4391
4387
|
});
|
|
@@ -4442,7 +4438,7 @@
|
|
|
4442
4438
|
tree: parentContext.tree,
|
|
4443
4439
|
context: parentContext.context,
|
|
4444
4440
|
parentId: parentContext.id,
|
|
4445
|
-
allParentIds:
|
|
4441
|
+
allParentIds: __spread(parentContext.allParentIds, [parentContext.id]),
|
|
4446
4442
|
rootId: parentContext.rootId,
|
|
4447
4443
|
parentEvent: parentContext,
|
|
4448
4444
|
parentActionEvent: parentActionContext
|
|
@@ -4622,7 +4618,7 @@
|
|
|
4622
4618
|
stringStartsWith(path, "./") ||
|
|
4623
4619
|
stringStartsWith(path, "../");
|
|
4624
4620
|
if (!valid) {
|
|
4625
|
-
throw fail("a json path must be either rooted, empty or relative, but got '"
|
|
4621
|
+
throw fail("a json path must be either rooted, empty or relative, but got '" + path + "'");
|
|
4626
4622
|
}
|
|
4627
4623
|
// '/a/b/c' -> ["a", "b", "c"]
|
|
4628
4624
|
// '../../b/c' -> ["..", "..", "b", "c"]
|
|
@@ -4668,7 +4664,7 @@
|
|
|
4668
4664
|
configurable: true,
|
|
4669
4665
|
writable: true,
|
|
4670
4666
|
value: function () {
|
|
4671
|
-
return "snapshotProcessor("
|
|
4667
|
+
return "snapshotProcessor(" + this._subtype.describe() + ")";
|
|
4672
4668
|
}
|
|
4673
4669
|
});
|
|
4674
4670
|
Object.defineProperty(SnapshotProcessor.prototype, "preProcessSnapshot", {
|
|
@@ -5084,7 +5080,7 @@
|
|
|
5084
5080
|
if (!type.identifierAttribute)
|
|
5085
5081
|
return current;
|
|
5086
5082
|
if (current && current !== type.identifierAttribute) {
|
|
5087
|
-
throw fail("The objects in a map should all have the same identifier attribute, expected '"
|
|
5083
|
+
throw fail("The objects in a map should all have the same identifier attribute, expected '" + current + "', but child of type '" + type.name + "' declared attribute '" + type.identifierAttribute + "' as identifier");
|
|
5088
5084
|
}
|
|
5089
5085
|
return type.identifierAttribute;
|
|
5090
5086
|
}, undefined);
|
|
@@ -5208,7 +5204,7 @@
|
|
|
5208
5204
|
if (this.identifierMode === MapIdentifierMode.YES && node instanceof ObjectNode) {
|
|
5209
5205
|
var identifier = node.identifier;
|
|
5210
5206
|
if (identifier !== expected)
|
|
5211
|
-
throw fail("A map of objects containing an identifier should always store the object under their own identifier. Trying to store key '"
|
|
5207
|
+
throw fail("A map of objects containing an identifier should always store the object under their own identifier. Trying to store key '" + identifier + "', but expected: '" + expected + "'");
|
|
5212
5208
|
}
|
|
5213
5209
|
}
|
|
5214
5210
|
});
|
|
@@ -5380,7 +5376,7 @@
|
|
|
5380
5376
|
* @returns
|
|
5381
5377
|
*/
|
|
5382
5378
|
function map(subtype) {
|
|
5383
|
-
return new MapType("Map<string, "
|
|
5379
|
+
return new MapType("Map<string, " + subtype.name + ">", subtype);
|
|
5384
5380
|
}
|
|
5385
5381
|
/**
|
|
5386
5382
|
* Returns if a given value represents a map type.
|
|
@@ -5697,7 +5693,7 @@
|
|
|
5697
5693
|
*/
|
|
5698
5694
|
function array(subtype) {
|
|
5699
5695
|
assertIsType(subtype, 1);
|
|
5700
|
-
return new ArrayType(
|
|
5696
|
+
return new ArrayType(subtype.name + "[]", subtype);
|
|
5701
5697
|
}
|
|
5702
5698
|
function reconcileArrayChildren(parent, childType, oldNodes, newValues, newPaths) {
|
|
5703
5699
|
var nothingChanged = true;
|
|
@@ -5731,7 +5727,7 @@
|
|
|
5731
5727
|
// check if already belongs to the same parent. if so, avoid pushing item in. only swapping can occur.
|
|
5732
5728
|
if (isStateTreeNode(newValue) && getStateTreeNode(newValue).parent === parent) {
|
|
5733
5729
|
// this node is owned by this parent, but not in the reconcilable set, so it must be double
|
|
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 '"
|
|
5730
|
+
throw fail("Cannot add an object to a state tree if it is already part of the same or another state tree. Tried to assign an object to '" + parent.path + "/" + newPath + "', but it lives already at '" + getStateTreeNode(newValue).path + "'");
|
|
5735
5731
|
}
|
|
5736
5732
|
nothingChanged = false;
|
|
5737
5733
|
var newNode = valueAsNode(childType, parent, newPath, newValue);
|
|
@@ -5847,7 +5843,7 @@
|
|
|
5847
5843
|
var alreadySeenKeys = new Set();
|
|
5848
5844
|
keysList.forEach(function (key) {
|
|
5849
5845
|
if (alreadySeenKeys.has(key)) {
|
|
5850
|
-
throw fail(
|
|
5846
|
+
throw fail(key + " is declared twice in the model. Model should not contain the same keys");
|
|
5851
5847
|
}
|
|
5852
5848
|
alreadySeenKeys.add(key);
|
|
5853
5849
|
});
|
|
@@ -5855,7 +5851,7 @@
|
|
|
5855
5851
|
return keysList.reduce(function (props, key) {
|
|
5856
5852
|
// warn if user intended a HOOK
|
|
5857
5853
|
if (key in Hook) {
|
|
5858
|
-
throw fail("Hook '"
|
|
5854
|
+
throw fail("Hook '" + key + "' was defined as property. Hooks should be defined as part of the actions");
|
|
5859
5855
|
}
|
|
5860
5856
|
// the user intended to use a view
|
|
5861
5857
|
var descriptor = Object.getOwnPropertyDescriptor(declaredProps, key);
|
|
@@ -5882,17 +5878,17 @@
|
|
|
5882
5878
|
else if (isType(value)) ;
|
|
5883
5879
|
// its a function, maybe the user wanted a view?
|
|
5884
5880
|
else if (typeof value === "function") {
|
|
5885
|
-
throw fail("Invalid type definition for property '"
|
|
5881
|
+
throw fail("Invalid type definition for property '" + key + "', it looks like you passed a function. Did you forget to invoke it, or did you intend to declare a view / action?");
|
|
5886
5882
|
}
|
|
5887
5883
|
// no other complex values
|
|
5888
5884
|
else if (typeof value === "object") {
|
|
5889
|
-
throw fail("Invalid type definition for property '"
|
|
5885
|
+
throw fail("Invalid type definition for property '" + key + "', it looks like you passed an object. Try passing another model type or a types.frozen.");
|
|
5890
5886
|
}
|
|
5891
5887
|
else {
|
|
5892
|
-
throw fail("Invalid type definition for property '"
|
|
5888
|
+
throw fail("Invalid type definition for property '" + key + "', cannot infer a type from a value like '" + value + "' (" + typeof value + ")");
|
|
5893
5889
|
}
|
|
5894
5890
|
return props;
|
|
5895
|
-
}, declaredProps);
|
|
5891
|
+
}, __assign({}, declaredProps));
|
|
5896
5892
|
}
|
|
5897
5893
|
/**
|
|
5898
5894
|
* @internal
|
|
@@ -6002,7 +5998,7 @@
|
|
|
6002
5998
|
this.forAllProps(function (propName, propType) {
|
|
6003
5999
|
if (propType.flags & TypeFlags.Identifier) {
|
|
6004
6000
|
if (identifierAttribute)
|
|
6005
|
-
throw fail("Cannot define property '"
|
|
6001
|
+
throw fail("Cannot define property '" + propName + "' as object identifier, property '" + identifierAttribute + "' is already defined as identifier property");
|
|
6006
6002
|
identifierAttribute = propName;
|
|
6007
6003
|
}
|
|
6008
6004
|
});
|
|
@@ -6048,10 +6044,10 @@
|
|
|
6048
6044
|
Object.keys(actions).forEach(function (name) {
|
|
6049
6045
|
// warn if preprocessor was given
|
|
6050
6046
|
if (name === PRE_PROCESS_SNAPSHOT)
|
|
6051
|
-
throw fail("Cannot define action '"
|
|
6047
|
+
throw fail("Cannot define action '" + PRE_PROCESS_SNAPSHOT + "', it should be defined using 'type.preProcessSnapshot(fn)' instead");
|
|
6052
6048
|
// warn if postprocessor was given
|
|
6053
6049
|
if (name === POST_PROCESS_SNAPSHOT)
|
|
6054
|
-
throw fail("Cannot define action '"
|
|
6050
|
+
throw fail("Cannot define action '" + POST_PROCESS_SNAPSHOT + "', it should be defined using 'type.postProcessSnapshot(fn)' instead");
|
|
6055
6051
|
var action2 = actions[name];
|
|
6056
6052
|
// apply hook composition
|
|
6057
6053
|
var baseAction = self[name];
|
|
@@ -6081,7 +6077,7 @@
|
|
|
6081
6077
|
value: function (fn) {
|
|
6082
6078
|
var _this = this;
|
|
6083
6079
|
if (typeof fn !== "function") {
|
|
6084
|
-
throw fail("You passed an "
|
|
6080
|
+
throw fail("You passed an " + typeof fn + " to volatile state as an argument, when function is expected");
|
|
6085
6081
|
}
|
|
6086
6082
|
var stateInitializer = function (self) {
|
|
6087
6083
|
_this.instantiateVolatileState(self, fn(self));
|
|
@@ -6110,7 +6106,7 @@
|
|
|
6110
6106
|
var initializer = function (self) {
|
|
6111
6107
|
var _a = fn(self), actions = _a.actions, views = _a.views, state = _a.state, rest = __rest(_a, ["actions", "views", "state"]);
|
|
6112
6108
|
for (var key in rest)
|
|
6113
|
-
throw fail("The `extend` function should return an object with a subset of the fields 'actions', 'views' and 'state'. Found invalid key '"
|
|
6109
|
+
throw fail("The `extend` function should return an object with a subset of the fields 'actions', 'views' and 'state'. Found invalid key '" + key + "'");
|
|
6114
6110
|
if (state)
|
|
6115
6111
|
_this.instantiateVolatileState(self, state);
|
|
6116
6112
|
if (views)
|
|
@@ -6294,7 +6290,7 @@
|
|
|
6294
6290
|
atom.reportObserved();
|
|
6295
6291
|
}
|
|
6296
6292
|
catch (e) {
|
|
6297
|
-
throw fail(
|
|
6293
|
+
throw fail(name + " property is declared twice");
|
|
6298
6294
|
}
|
|
6299
6295
|
res[name] = _this.getChildNode(node, name).snapshot;
|
|
6300
6296
|
});
|
|
@@ -6322,7 +6318,7 @@
|
|
|
6322
6318
|
writable: true,
|
|
6323
6319
|
value: function (node, subpath, patch) {
|
|
6324
6320
|
if (!(patch.op === "replace" || patch.op === "add")) {
|
|
6325
|
-
throw fail("object does not support operation "
|
|
6321
|
+
throw fail("object does not support operation " + patch.op);
|
|
6326
6322
|
}
|
|
6327
6323
|
node.storedValue[subpath] = patch.value;
|
|
6328
6324
|
}
|
|
@@ -6554,7 +6550,7 @@
|
|
|
6554
6550
|
return typeCheckSuccess();
|
|
6555
6551
|
}
|
|
6556
6552
|
var typeName = this.name === "Date" ? "Date or a unix milliseconds timestamp" : this.name;
|
|
6557
|
-
return typeCheckFailure(context, value, "Value is not a "
|
|
6553
|
+
return typeCheckFailure(context, value, "Value is not a " + typeName);
|
|
6558
6554
|
}
|
|
6559
6555
|
});
|
|
6560
6556
|
return CoreType;
|
|
@@ -6747,7 +6743,7 @@
|
|
|
6747
6743
|
if (isPrimitive(value) && value === this.value) {
|
|
6748
6744
|
return typeCheckSuccess();
|
|
6749
6745
|
}
|
|
6750
|
-
return typeCheckFailure(context, value, "Value is not a literal "
|
|
6746
|
+
return typeCheckFailure(context, value, "Value is not a literal " + JSON.stringify(this.value));
|
|
6751
6747
|
}
|
|
6752
6748
|
});
|
|
6753
6749
|
return Literal;
|
|
@@ -6929,7 +6925,7 @@
|
|
|
6929
6925
|
assertIsString(option, i + 1);
|
|
6930
6926
|
});
|
|
6931
6927
|
}
|
|
6932
|
-
var type = union.apply(void 0,
|
|
6928
|
+
var type = union.apply(void 0, __spread(realOptions.map(function (option) { return literal("" + option); })));
|
|
6933
6929
|
if (typeof name === "string")
|
|
6934
6930
|
type.name = name;
|
|
6935
6931
|
return type;
|
|
@@ -7025,7 +7021,7 @@
|
|
|
7025
7021
|
if (this._dispatcher) {
|
|
7026
7022
|
return this._dispatcher(value);
|
|
7027
7023
|
}
|
|
7028
|
-
// find the most
|
|
7024
|
+
// find the most accomodating type
|
|
7029
7025
|
// if we are using reconciliation try the current node type first (fix for #1045)
|
|
7030
7026
|
if (reconcileCurrentType) {
|
|
7031
7027
|
if (reconcileCurrentType.is(value)) {
|
|
@@ -7089,7 +7085,7 @@
|
|
|
7089
7085
|
otherTypes[_i - 1] = arguments[_i];
|
|
7090
7086
|
}
|
|
7091
7087
|
var options = isType(optionsOrType) ? undefined : optionsOrType;
|
|
7092
|
-
var types = isType(optionsOrType) ?
|
|
7088
|
+
var types = isType(optionsOrType) ? __spread([optionsOrType], otherTypes) : otherTypes;
|
|
7093
7089
|
var name = "(" + types.map(function (type) { return type.name; }).join(" | ") + ")";
|
|
7094
7090
|
// check all options
|
|
7095
7091
|
{
|
|
@@ -7451,7 +7447,7 @@
|
|
|
7451
7447
|
* @returns
|
|
7452
7448
|
*/
|
|
7453
7449
|
function late(nameOrType, maybeType) {
|
|
7454
|
-
var name = typeof nameOrType === "string" ? nameOrType : "late("
|
|
7450
|
+
var name = typeof nameOrType === "string" ? nameOrType : "late(" + nameOrType.toString() + ")";
|
|
7455
7451
|
var type = typeof nameOrType === "string" ? maybeType : nameOrType;
|
|
7456
7452
|
// checks that the type is actually a late type
|
|
7457
7453
|
{
|
|
@@ -7523,7 +7519,7 @@
|
|
|
7523
7519
|
node.parent.applyPatches([
|
|
7524
7520
|
{
|
|
7525
7521
|
op: "replace",
|
|
7526
|
-
path: "/"
|
|
7522
|
+
path: "/" + node.subpath,
|
|
7527
7523
|
value: node.snapshot
|
|
7528
7524
|
}
|
|
7529
7525
|
]);
|
|
@@ -7537,7 +7533,7 @@
|
|
|
7537
7533
|
configurable: true,
|
|
7538
7534
|
writable: true,
|
|
7539
7535
|
value: function () {
|
|
7540
|
-
return "<lazy "
|
|
7536
|
+
return "<lazy " + this.name + ">";
|
|
7541
7537
|
}
|
|
7542
7538
|
});
|
|
7543
7539
|
Object.defineProperty(Lazy.prototype, "instantiate", {
|
|
@@ -7591,7 +7587,7 @@
|
|
|
7591
7587
|
var Frozen = /** @class */ (function (_super) {
|
|
7592
7588
|
__extends(Frozen, _super);
|
|
7593
7589
|
function Frozen(subType) {
|
|
7594
|
-
var _this = _super.call(this, subType ? "frozen("
|
|
7590
|
+
var _this = _super.call(this, subType ? "frozen(" + subType.name + ")" : "frozen") || this;
|
|
7595
7591
|
Object.defineProperty(_this, "subType", {
|
|
7596
7592
|
enumerable: true,
|
|
7597
7593
|
configurable: true,
|
|
@@ -7747,7 +7743,7 @@
|
|
|
7747
7743
|
this.identifier = id;
|
|
7748
7744
|
}
|
|
7749
7745
|
else {
|
|
7750
|
-
throw fail("Can only store references to tree nodes or identifiers, got: '"
|
|
7746
|
+
throw fail("Can only store references to tree nodes or identifiers, got: '" + value + "'");
|
|
7751
7747
|
}
|
|
7752
7748
|
}
|
|
7753
7749
|
Object.defineProperty(StoredReference.prototype, "updateResolvedReference", {
|
|
@@ -7764,7 +7760,7 @@
|
|
|
7764
7760
|
// reference was initialized with the identifier of the target
|
|
7765
7761
|
var target = root.identifierCache.resolve(targetType, normalizedId);
|
|
7766
7762
|
if (!target) {
|
|
7767
|
-
throw new InvalidReferenceError("[mobx-state-tree] Failed to resolve reference '"
|
|
7763
|
+
throw new InvalidReferenceError("[mobx-state-tree] Failed to resolve reference '" + this.identifier + "' to type '" + this.targetType.name + "' (from node: " + node.path + ")");
|
|
7768
7764
|
}
|
|
7769
7765
|
this.resolvedReference = {
|
|
7770
7766
|
node: target,
|
|
@@ -7803,7 +7799,7 @@
|
|
|
7803
7799
|
var BaseReferenceType = /** @class */ (function (_super) {
|
|
7804
7800
|
__extends(BaseReferenceType, _super);
|
|
7805
7801
|
function BaseReferenceType(targetType, onInvalidated) {
|
|
7806
|
-
var _this = _super.call(this, "reference("
|
|
7802
|
+
var _this = _super.call(this, "reference(" + targetType.name + ")") || this;
|
|
7807
7803
|
Object.defineProperty(_this, "targetType", {
|
|
7808
7804
|
enumerable: true,
|
|
7809
7805
|
configurable: true,
|
|
@@ -8228,7 +8224,7 @@
|
|
|
8228
8224
|
value: function (current, newValue, parent, subpath) {
|
|
8229
8225
|
// we don't consider detaching here since identifier are scalar nodes, and scalar nodes cannot be detached
|
|
8230
8226
|
if (current.storedValue !== newValue)
|
|
8231
|
-
throw fail("Tried to change identifier from '"
|
|
8227
|
+
throw fail("Tried to change identifier from '" + current.storedValue + "' to '" + newValue + "'. Changing identifiers is not allowed.");
|
|
8232
8228
|
current.setParent(parent, subpath);
|
|
8233
8229
|
return current;
|
|
8234
8230
|
}
|
|
@@ -8239,7 +8235,7 @@
|
|
|
8239
8235
|
writable: true,
|
|
8240
8236
|
value: function (value, context) {
|
|
8241
8237
|
if (typeof value !== this.validType) {
|
|
8242
|
-
return typeCheckFailure(context, value, "Value is not a valid "
|
|
8238
|
+
return typeCheckFailure(context, value, "Value is not a valid " + this.describe() + ", expected a " + this.validType);
|
|
8243
8239
|
}
|
|
8244
8240
|
return typeCheckSuccess();
|
|
8245
8241
|
}
|
|
@@ -8450,7 +8446,7 @@
|
|
|
8450
8446
|
return typeCheckSuccess();
|
|
8451
8447
|
var typeError = this.options.getValidationMessage(value);
|
|
8452
8448
|
if (typeError) {
|
|
8453
|
-
return typeCheckFailure(context, value, "Invalid value for type '"
|
|
8449
|
+
return typeCheckFailure(context, value, "Invalid value for type '" + this.name + "': " + typeError);
|
|
8454
8450
|
}
|
|
8455
8451
|
return typeCheckSuccess();
|
|
8456
8452
|
}
|
|
@@ -8614,4 +8610,4 @@
|
|
|
8614
8610
|
|
|
8615
8611
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
8616
8612
|
|
|
8617
|
-
}));
|
|
8613
|
+
})));
|