mobx-state-tree 5.4.0 → 5.4.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/mobx-state-tree.js +90 -90
- package/dist/mobx-state-tree.module.js +90 -90
- package/dist/mobx-state-tree.umd.js +90 -90
- package/package.json +1 -1
package/dist/mobx-state-tree.js
CHANGED
|
@@ -348,7 +348,7 @@ function protect(target) {
|
|
|
348
348
|
assertIsStateTreeNode(target, 1);
|
|
349
349
|
var node = getStateTreeNode(target);
|
|
350
350
|
if (!node.isRoot)
|
|
351
|
-
throw fail
|
|
351
|
+
throw fail("`protect` can only be invoked on root nodes");
|
|
352
352
|
node.isProtectionEnabled = true;
|
|
353
353
|
}
|
|
354
354
|
/**
|
|
@@ -380,7 +380,7 @@ function unprotect(target) {
|
|
|
380
380
|
assertIsStateTreeNode(target, 1);
|
|
381
381
|
var node = getStateTreeNode(target);
|
|
382
382
|
if (!node.isRoot)
|
|
383
|
-
throw fail
|
|
383
|
+
throw fail("`unprotect` can only be invoked on root nodes");
|
|
384
384
|
node.isProtectionEnabled = false;
|
|
385
385
|
}
|
|
386
386
|
/**
|
|
@@ -463,7 +463,7 @@ function getParent(target, depth) {
|
|
|
463
463
|
return parent.storedValue;
|
|
464
464
|
parent = parent.parent;
|
|
465
465
|
}
|
|
466
|
-
throw fail
|
|
466
|
+
throw fail("Failed to find the parent of " + getStateTreeNode(target) + " at depth " + depth);
|
|
467
467
|
}
|
|
468
468
|
/**
|
|
469
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
|
|
@@ -501,7 +501,7 @@ function getParentOfType(target, type) {
|
|
|
501
501
|
return parent.storedValue;
|
|
502
502
|
parent = parent.parent;
|
|
503
503
|
}
|
|
504
|
-
throw fail
|
|
504
|
+
throw fail("Failed to find the parent of " + getStateTreeNode(target) + " of a given type");
|
|
505
505
|
}
|
|
506
506
|
/**
|
|
507
507
|
* Given an object in a model tree, returns the root object of that tree.
|
|
@@ -618,7 +618,7 @@ function tryReference(getter, checkIfAlive) {
|
|
|
618
618
|
}
|
|
619
619
|
}
|
|
620
620
|
else {
|
|
621
|
-
throw fail
|
|
621
|
+
throw fail("The reference to be checked is not one of node, null or undefined");
|
|
622
622
|
}
|
|
623
623
|
}
|
|
624
624
|
catch (e) {
|
|
@@ -646,7 +646,7 @@ function isValidReference(getter, checkIfAlive) {
|
|
|
646
646
|
return checkIfAlive ? isAlive(node) : true;
|
|
647
647
|
}
|
|
648
648
|
else {
|
|
649
|
-
throw fail
|
|
649
|
+
throw fail("The reference to be checked is not one of node, null or undefined");
|
|
650
650
|
}
|
|
651
651
|
}
|
|
652
652
|
catch (e) {
|
|
@@ -1301,7 +1301,7 @@ var ScalarNode = /** @class */ (function (_super) {
|
|
|
1301
1301
|
get: function () {
|
|
1302
1302
|
// future optimization: store root ref in the node and maintain it
|
|
1303
1303
|
if (!this.parent)
|
|
1304
|
-
throw fail
|
|
1304
|
+
throw fail("This scalar node is not part of a tree");
|
|
1305
1305
|
return this.parent.root;
|
|
1306
1306
|
},
|
|
1307
1307
|
enumerable: false,
|
|
@@ -1320,15 +1320,15 @@ var ScalarNode = /** @class */ (function (_super) {
|
|
|
1320
1320
|
if (devMode()) {
|
|
1321
1321
|
if (!subpath) {
|
|
1322
1322
|
// istanbul ignore next
|
|
1323
|
-
throw fail
|
|
1323
|
+
throw fail("assertion failed: subpath expected");
|
|
1324
1324
|
}
|
|
1325
1325
|
if (!newParent) {
|
|
1326
1326
|
// istanbul ignore next
|
|
1327
|
-
throw fail
|
|
1327
|
+
throw fail("assertion failed: parent expected");
|
|
1328
1328
|
}
|
|
1329
1329
|
if (parentChanged) {
|
|
1330
1330
|
// istanbul ignore next
|
|
1331
|
-
throw fail
|
|
1331
|
+
throw fail("assertion failed: scalar nodes cannot change their parent");
|
|
1332
1332
|
}
|
|
1333
1333
|
}
|
|
1334
1334
|
this.environment = undefined; // use parent's
|
|
@@ -1569,7 +1569,7 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
1569
1569
|
}
|
|
1570
1570
|
}
|
|
1571
1571
|
if (typeof id !== "string" && typeof id !== "number") {
|
|
1572
|
-
throw fail
|
|
1572
|
+
throw fail("Instance identifier '" + _this.identifierAttribute + "' for type '" + _this.type.name + "' must be a string or a number");
|
|
1573
1573
|
}
|
|
1574
1574
|
// normalize internal identifier to string
|
|
1575
1575
|
_this.identifier = normalizeIdentifier(id);
|
|
@@ -1622,7 +1622,7 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
1622
1622
|
if (devMode()) {
|
|
1623
1623
|
if (this.state !== NodeLifeCycle.INITIALIZING) {
|
|
1624
1624
|
// istanbul ignore next
|
|
1625
|
-
throw fail
|
|
1625
|
+
throw fail("assertion failed: the creation of the observable instance must be done on the initializing phase");
|
|
1626
1626
|
}
|
|
1627
1627
|
}
|
|
1628
1628
|
this._observableInstanceState = 1 /* CREATING */;
|
|
@@ -1745,20 +1745,20 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
1745
1745
|
if (devMode()) {
|
|
1746
1746
|
if (!subpath) {
|
|
1747
1747
|
// istanbul ignore next
|
|
1748
|
-
throw fail
|
|
1748
|
+
throw fail("assertion failed: subpath expected");
|
|
1749
1749
|
}
|
|
1750
1750
|
if (!newParent) {
|
|
1751
1751
|
// istanbul ignore next
|
|
1752
|
-
throw fail
|
|
1752
|
+
throw fail("assertion failed: new parent expected");
|
|
1753
1753
|
}
|
|
1754
1754
|
if (this.parent && parentChanged) {
|
|
1755
|
-
throw fail
|
|
1755
|
+
throw fail("A node cannot exists twice in the state tree. Failed to add " + this + " to path '" + newParent.path + "/" + subpath + "'.");
|
|
1756
1756
|
}
|
|
1757
1757
|
if (!this.parent && newParent.root === this) {
|
|
1758
|
-
throw fail
|
|
1758
|
+
throw fail("A state tree is not allowed to contain itself. Cannot assign " + this + " to path '" + newParent.path + "/" + subpath + "'");
|
|
1759
1759
|
}
|
|
1760
1760
|
if (!this.parent && !!this.environment && this.environment !== newParent.root.environment) {
|
|
1761
|
-
throw fail
|
|
1761
|
+
throw fail("A state tree cannot be made part of another state tree as long as their environments are different.");
|
|
1762
1762
|
}
|
|
1763
1763
|
}
|
|
1764
1764
|
if (parentChanged) {
|
|
@@ -1864,7 +1864,7 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
1864
1864
|
var error = this._getAssertAliveError(context);
|
|
1865
1865
|
switch (livelinessChecking) {
|
|
1866
1866
|
case "error":
|
|
1867
|
-
throw fail
|
|
1867
|
+
throw fail(error);
|
|
1868
1868
|
case "warn":
|
|
1869
1869
|
warnError(error);
|
|
1870
1870
|
}
|
|
@@ -1950,7 +1950,7 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
1950
1950
|
value: function (context) {
|
|
1951
1951
|
this.assertAlive(context);
|
|
1952
1952
|
if (!this.isRunningAction() && this.isProtected) {
|
|
1953
|
-
throw fail
|
|
1953
|
+
throw fail("Cannot modify '" + this + "', the object is protected and can only be modified by using an action.");
|
|
1954
1954
|
}
|
|
1955
1955
|
}
|
|
1956
1956
|
});
|
|
@@ -2017,7 +2017,7 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
2017
2017
|
writable: true,
|
|
2018
2018
|
value: function () {
|
|
2019
2019
|
if (!this.isAlive)
|
|
2020
|
-
throw fail
|
|
2020
|
+
throw fail("Error while detaching, node is not alive.");
|
|
2021
2021
|
this.clearParent();
|
|
2022
2022
|
}
|
|
2023
2023
|
});
|
|
@@ -2153,7 +2153,7 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
2153
2153
|
this._internalEventsRegister("dispose" /* Dispose */, disposer, true);
|
|
2154
2154
|
return;
|
|
2155
2155
|
}
|
|
2156
|
-
throw fail
|
|
2156
|
+
throw fail("cannot add a disposer when it is already registered for execution");
|
|
2157
2157
|
}
|
|
2158
2158
|
});
|
|
2159
2159
|
Object.defineProperty(ObjectNode.prototype, "removeDisposer", {
|
|
@@ -2162,7 +2162,7 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
2162
2162
|
writable: true,
|
|
2163
2163
|
value: function (disposer) {
|
|
2164
2164
|
if (!this._internalEventsHas("dispose" /* Dispose */, disposer)) {
|
|
2165
|
-
throw fail
|
|
2165
|
+
throw fail("cannot remove a disposer which was never registered for execution");
|
|
2166
2166
|
}
|
|
2167
2167
|
this._internalEventsUnregister("dispose" /* Dispose */, disposer);
|
|
2168
2168
|
}
|
|
@@ -2408,7 +2408,7 @@ var BaseType = /** @class */ (function () {
|
|
|
2408
2408
|
writable: true,
|
|
2409
2409
|
value: function (node, applyPostProcess) {
|
|
2410
2410
|
// istanbul ignore next
|
|
2411
|
-
throw fail
|
|
2411
|
+
throw fail("unimplemented method");
|
|
2412
2412
|
}
|
|
2413
2413
|
});
|
|
2414
2414
|
Object.defineProperty(BaseType.prototype, "isAssignableFrom", {
|
|
@@ -2446,7 +2446,7 @@ var BaseType = /** @class */ (function () {
|
|
|
2446
2446
|
Object.defineProperty(BaseType.prototype, "Type", {
|
|
2447
2447
|
get: function () {
|
|
2448
2448
|
// istanbul ignore next
|
|
2449
|
-
throw fail
|
|
2449
|
+
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
2450
|
},
|
|
2451
2451
|
enumerable: false,
|
|
2452
2452
|
configurable: true
|
|
@@ -2454,7 +2454,7 @@ var BaseType = /** @class */ (function () {
|
|
|
2454
2454
|
Object.defineProperty(BaseType.prototype, "TypeWithoutSTN", {
|
|
2455
2455
|
get: function () {
|
|
2456
2456
|
// istanbul ignore next
|
|
2457
|
-
throw fail
|
|
2457
|
+
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
2458
|
},
|
|
2459
2459
|
enumerable: false,
|
|
2460
2460
|
configurable: true
|
|
@@ -2462,7 +2462,7 @@ var BaseType = /** @class */ (function () {
|
|
|
2462
2462
|
Object.defineProperty(BaseType.prototype, "SnapshotType", {
|
|
2463
2463
|
get: function () {
|
|
2464
2464
|
// istanbul ignore next
|
|
2465
|
-
throw fail
|
|
2465
|
+
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
2466
|
},
|
|
2467
2467
|
enumerable: false,
|
|
2468
2468
|
configurable: true
|
|
@@ -2470,7 +2470,7 @@ var BaseType = /** @class */ (function () {
|
|
|
2470
2470
|
Object.defineProperty(BaseType.prototype, "CreationType", {
|
|
2471
2471
|
get: function () {
|
|
2472
2472
|
// istanbul ignore next
|
|
2473
|
-
throw fail
|
|
2473
|
+
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
2474
|
},
|
|
2475
2475
|
enumerable: false,
|
|
2476
2476
|
configurable: true
|
|
@@ -2960,7 +2960,7 @@ function applyAction(target, actions) {
|
|
|
2960
2960
|
function baseApplyAction(target, action) {
|
|
2961
2961
|
var resolvedTarget = tryResolve(target, action.path || "");
|
|
2962
2962
|
if (!resolvedTarget)
|
|
2963
|
-
throw fail
|
|
2963
|
+
throw fail("Invalid action path: " + (action.path || ""));
|
|
2964
2964
|
var node = getStateTreeNode(resolvedTarget);
|
|
2965
2965
|
// Reserved functions
|
|
2966
2966
|
if (action.name === "@APPLY_PATCHES") {
|
|
@@ -2970,7 +2970,7 @@ function baseApplyAction(target, action) {
|
|
|
2970
2970
|
return applySnapshot.call(null, resolvedTarget, action.args[0]);
|
|
2971
2971
|
}
|
|
2972
2972
|
if (!(typeof resolvedTarget[action.name] === "function"))
|
|
2973
|
-
throw fail
|
|
2973
|
+
throw fail("Action '" + action.name + "' does not exist in '" + node.path + "'");
|
|
2974
2974
|
return resolvedTarget[action.name].apply(resolvedTarget, action.args ? action.args.map(function (v) { return deserializeArgument(node, v); }) : []);
|
|
2975
2975
|
}
|
|
2976
2976
|
/**
|
|
@@ -3331,11 +3331,11 @@ function runMiddleWares(node, baseCall, originalFn) {
|
|
|
3331
3331
|
if (devMode()) {
|
|
3332
3332
|
if (!nextInvoked && !abortInvoked) {
|
|
3333
3333
|
var node2 = getStateTreeNode(call.tree);
|
|
3334
|
-
throw fail
|
|
3334
|
+
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.");
|
|
3335
3335
|
}
|
|
3336
3336
|
else if (nextInvoked && abortInvoked) {
|
|
3337
3337
|
var node2 = getStateTreeNode(call.tree);
|
|
3338
|
-
throw fail
|
|
3338
|
+
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.");
|
|
3339
3339
|
}
|
|
3340
3340
|
}
|
|
3341
3341
|
return result;
|
|
@@ -3482,7 +3482,7 @@ function typecheckInternal(type, value) {
|
|
|
3482
3482
|
function typecheck(type, value) {
|
|
3483
3483
|
var errors = type.validate(value, [{ path: "", type: type }]);
|
|
3484
3484
|
if (errors.length > 0) {
|
|
3485
|
-
throw fail
|
|
3485
|
+
throw fail(validationErrorsToString(type, value, errors));
|
|
3486
3486
|
}
|
|
3487
3487
|
}
|
|
3488
3488
|
function validationErrorsToString(type, value, errors) {
|
|
@@ -3553,7 +3553,7 @@ var IdentifierCache = /** @class */ (function () {
|
|
|
3553
3553
|
}
|
|
3554
3554
|
var set = this.cache.get(identifier);
|
|
3555
3555
|
if (set.indexOf(node) !== -1)
|
|
3556
|
-
throw fail
|
|
3556
|
+
throw fail("Already registered");
|
|
3557
3557
|
set.push(node);
|
|
3558
3558
|
if (lastCacheUpdate) {
|
|
3559
3559
|
this.updateLastCacheModificationPerId(identifier);
|
|
@@ -3652,7 +3652,7 @@ var IdentifierCache = /** @class */ (function () {
|
|
|
3652
3652
|
case 1:
|
|
3653
3653
|
return matches[0];
|
|
3654
3654
|
default:
|
|
3655
|
-
throw fail
|
|
3655
|
+
throw fail("Cannot resolve a reference to type '" + type.name + "' with id: '" + identifier + "' unambigously, there are multiple candidates: " + matches
|
|
3656
3656
|
.map(function (n) { return n.path; })
|
|
3657
3657
|
.join(", "));
|
|
3658
3658
|
}
|
|
@@ -3670,7 +3670,7 @@ function createObjectNode(type, parent, subpath, environment, initialValue) {
|
|
|
3670
3670
|
if (existingNode) {
|
|
3671
3671
|
if (existingNode.parent) {
|
|
3672
3672
|
// istanbul ignore next
|
|
3673
|
-
throw fail
|
|
3673
|
+
throw fail("Cannot add an object to a state tree if it is already part of the same or another state tree. Tried to assign an object to '" + (parent ? parent.path : "") + "/" + subpath + "', but it lives already at '" + existingNode.path + "'");
|
|
3674
3674
|
}
|
|
3675
3675
|
if (parent) {
|
|
3676
3676
|
existingNode.setParent(parent, subpath);
|
|
@@ -3733,7 +3733,7 @@ function assertIsStateTreeNode(value, argNumber) {
|
|
|
3733
3733
|
function getStateTreeNode(value) {
|
|
3734
3734
|
if (!isStateTreeNode(value)) {
|
|
3735
3735
|
// istanbul ignore next
|
|
3736
|
-
throw fail
|
|
3736
|
+
throw fail("Value " + value + " is no MST Node");
|
|
3737
3737
|
}
|
|
3738
3738
|
return value.$treenode;
|
|
3739
3739
|
}
|
|
@@ -3759,7 +3759,7 @@ var doubleDot = function (_) { return ".."; };
|
|
|
3759
3759
|
function getRelativePathBetweenNodes(base, target) {
|
|
3760
3760
|
// PRE condition target is (a child of) base!
|
|
3761
3761
|
if (base.root !== target.root) {
|
|
3762
|
-
throw fail
|
|
3762
|
+
throw fail("Cannot calculate relative path: objects '" + base + "' and '" + target + "' are not part of the same object tree");
|
|
3763
3763
|
}
|
|
3764
3764
|
var baseParts = splitJsonPath(base.path);
|
|
3765
3765
|
var targetParts = splitJsonPath(target.path);
|
|
@@ -3816,7 +3816,7 @@ function resolveNodeByPathParts(base, pathParts, failIfResolveFails) {
|
|
|
3816
3816
|
}
|
|
3817
3817
|
}
|
|
3818
3818
|
}
|
|
3819
|
-
throw fail
|
|
3819
|
+
throw fail("Could not resolve '" + part + "' in path '" + (joinJsonPath(pathParts.slice(0, i)) || "/") + "' while resolving '" + joinJsonPath(pathParts) + "'");
|
|
3820
3820
|
}
|
|
3821
3821
|
}
|
|
3822
3822
|
catch (e) {
|
|
@@ -3892,7 +3892,7 @@ Object.freeze(mobxShallow);
|
|
|
3892
3892
|
* @internal
|
|
3893
3893
|
* @hidden
|
|
3894
3894
|
*/
|
|
3895
|
-
function fail
|
|
3895
|
+
function fail(message) {
|
|
3896
3896
|
if (message === void 0) { message = "Illegal state"; }
|
|
3897
3897
|
return new Error("[mobx-state-tree] " + message);
|
|
3898
3898
|
}
|
|
@@ -4299,7 +4299,7 @@ function assertArg(value, fn, typeName, argNumber) {
|
|
|
4299
4299
|
if (devMode()) {
|
|
4300
4300
|
if (!fn(value)) {
|
|
4301
4301
|
// istanbul ignore next
|
|
4302
|
-
throw fail
|
|
4302
|
+
throw fail("expected " + typeName + " as argument " + asArray(argNumber).join(" or ") + ", got " + value + " instead");
|
|
4303
4303
|
}
|
|
4304
4304
|
}
|
|
4305
4305
|
}
|
|
@@ -4444,11 +4444,11 @@ function createFlowSpawner(name, generator) {
|
|
|
4444
4444
|
var runId = getNextActionId();
|
|
4445
4445
|
var parentContext = getCurrentActionContext();
|
|
4446
4446
|
if (!parentContext) {
|
|
4447
|
-
throw fail
|
|
4447
|
+
throw fail("a mst flow must always have a parent context");
|
|
4448
4448
|
}
|
|
4449
4449
|
var parentActionContext = getParentActionContext(parentContext);
|
|
4450
4450
|
if (!parentActionContext) {
|
|
4451
|
-
throw fail
|
|
4451
|
+
throw fail("a mst flow must always have a parent action context");
|
|
4452
4452
|
}
|
|
4453
4453
|
var contextBase = {
|
|
4454
4454
|
name: name,
|
|
@@ -4519,7 +4519,7 @@ function createFlowSpawner(name, generator) {
|
|
|
4519
4519
|
// TODO: support more type of values? See https://github.com/tj/co/blob/249bbdc72da24ae44076afd716349d2089b31c4c/index.js#L100
|
|
4520
4520
|
if (!ret.value || typeof ret.value.then !== "function") {
|
|
4521
4521
|
// istanbul ignore next
|
|
4522
|
-
throw fail
|
|
4522
|
+
throw fail("Only promises can be yielded to `async`, got: " + ret);
|
|
4523
4523
|
}
|
|
4524
4524
|
return ret.value.then(onFulfilled, onRejected);
|
|
4525
4525
|
}
|
|
@@ -4535,7 +4535,7 @@ function createFlowSpawner(name, generator) {
|
|
|
4535
4535
|
*/
|
|
4536
4536
|
function splitPatch(patch) {
|
|
4537
4537
|
if (!("oldValue" in patch))
|
|
4538
|
-
throw fail
|
|
4538
|
+
throw fail("Patches without `oldValue` field cannot be inversed");
|
|
4539
4539
|
return [stripPatch(patch), invertPatch(patch)];
|
|
4540
4540
|
}
|
|
4541
4541
|
/**
|
|
@@ -4636,7 +4636,7 @@ function splitJsonPath(path) {
|
|
|
4636
4636
|
stringStartsWith(path, "./") ||
|
|
4637
4637
|
stringStartsWith(path, "../");
|
|
4638
4638
|
if (!valid) {
|
|
4639
|
-
throw fail
|
|
4639
|
+
throw fail("a json path must be either rooted, empty or relative, but got '" + path + "'");
|
|
4640
4640
|
}
|
|
4641
4641
|
// '/a/b/c' -> ["a", "b", "c"]
|
|
4642
4642
|
// '../../b/c' -> ["..", "..", "b", "c"]
|
|
@@ -4984,28 +4984,28 @@ var MSTMap = /** @class */ (function (_super) {
|
|
|
4984
4984
|
writable: true,
|
|
4985
4985
|
value: function (value) {
|
|
4986
4986
|
if (!value)
|
|
4987
|
-
throw fail
|
|
4987
|
+
throw fail("Map.put cannot be used to set empty values");
|
|
4988
4988
|
if (isStateTreeNode(value)) {
|
|
4989
4989
|
var node = getStateTreeNode(value);
|
|
4990
4990
|
if (devMode()) {
|
|
4991
4991
|
if (!node.identifierAttribute) {
|
|
4992
|
-
throw fail
|
|
4992
|
+
throw fail(needsIdentifierError);
|
|
4993
4993
|
}
|
|
4994
4994
|
}
|
|
4995
4995
|
if (node.identifier === null) {
|
|
4996
|
-
throw fail
|
|
4996
|
+
throw fail(needsIdentifierError);
|
|
4997
4997
|
}
|
|
4998
4998
|
this.set(node.identifier, value);
|
|
4999
4999
|
return value;
|
|
5000
5000
|
}
|
|
5001
5001
|
else if (!isMutable(value)) {
|
|
5002
|
-
throw fail
|
|
5002
|
+
throw fail("Map.put can only be used to store complex values");
|
|
5003
5003
|
}
|
|
5004
5004
|
else {
|
|
5005
5005
|
var mapNode = getStateTreeNode(this);
|
|
5006
5006
|
var mapType = mapNode.type;
|
|
5007
5007
|
if (mapType.identifierMode !== MapIdentifierMode.YES) {
|
|
5008
|
-
throw fail
|
|
5008
|
+
throw fail(needsIdentifierError);
|
|
5009
5009
|
}
|
|
5010
5010
|
var idAttr = mapType.mapIdentifierAttribute;
|
|
5011
5011
|
var id = value[idAttr];
|
|
@@ -5098,7 +5098,7 @@ var MapType = /** @class */ (function (_super) {
|
|
|
5098
5098
|
if (!type.identifierAttribute)
|
|
5099
5099
|
return current;
|
|
5100
5100
|
if (current && current !== type.identifierAttribute) {
|
|
5101
|
-
throw fail
|
|
5101
|
+
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");
|
|
5102
5102
|
}
|
|
5103
5103
|
return type.identifierAttribute;
|
|
5104
5104
|
}, undefined);
|
|
@@ -5177,7 +5177,7 @@ var MapType = /** @class */ (function (_super) {
|
|
|
5177
5177
|
value: function (node, key) {
|
|
5178
5178
|
var childNode = node.storedValue.get("" + key);
|
|
5179
5179
|
if (!childNode)
|
|
5180
|
-
throw fail
|
|
5180
|
+
throw fail("Not a child " + key);
|
|
5181
5181
|
return childNode;
|
|
5182
5182
|
}
|
|
5183
5183
|
});
|
|
@@ -5222,7 +5222,7 @@ var MapType = /** @class */ (function (_super) {
|
|
|
5222
5222
|
if (this.identifierMode === MapIdentifierMode.YES && node instanceof ObjectNode) {
|
|
5223
5223
|
var identifier = node.identifier;
|
|
5224
5224
|
if (identifier !== expected)
|
|
5225
|
-
throw fail
|
|
5225
|
+
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 + "'");
|
|
5226
5226
|
}
|
|
5227
5227
|
}
|
|
5228
5228
|
});
|
|
@@ -5520,7 +5520,7 @@ var ArrayType = /** @class */ (function (_super) {
|
|
|
5520
5520
|
var index = Number(key);
|
|
5521
5521
|
if (index < node.storedValue.length)
|
|
5522
5522
|
return node.storedValue[index];
|
|
5523
|
-
throw fail
|
|
5523
|
+
throw fail("Not a child: " + key);
|
|
5524
5524
|
}
|
|
5525
5525
|
});
|
|
5526
5526
|
Object.defineProperty(ArrayType.prototype, "willChange", {
|
|
@@ -5745,7 +5745,7 @@ function reconcileArrayChildren(parent, childType, oldNodes, newValues, newPaths
|
|
|
5745
5745
|
// check if already belongs to the same parent. if so, avoid pushing item in. only swapping can occur.
|
|
5746
5746
|
if (isStateTreeNode(newValue) && getStateTreeNode(newValue).parent === parent) {
|
|
5747
5747
|
// this node is owned by this parent, but not in the reconcilable set, so it must be double
|
|
5748
|
-
throw fail
|
|
5748
|
+
throw fail("Cannot add an object to a state tree if it is already part of the same or another state tree. Tried to assign an object to '" + parent.path + "/" + newPath + "', but it lives already at '" + getStateTreeNode(newValue).path + "'");
|
|
5749
5749
|
}
|
|
5750
5750
|
nothingChanged = false;
|
|
5751
5751
|
var newNode = valueAsNode(childType, parent, newPath, newValue);
|
|
@@ -5861,7 +5861,7 @@ function toPropertiesObject(declaredProps) {
|
|
|
5861
5861
|
var alreadySeenKeys = new Set();
|
|
5862
5862
|
keysList.forEach(function (key) {
|
|
5863
5863
|
if (alreadySeenKeys.has(key)) {
|
|
5864
|
-
throw fail
|
|
5864
|
+
throw fail(key + " is declared twice in the model. Model should not contain the same keys");
|
|
5865
5865
|
}
|
|
5866
5866
|
alreadySeenKeys.add(key);
|
|
5867
5867
|
});
|
|
@@ -5869,17 +5869,17 @@ function toPropertiesObject(declaredProps) {
|
|
|
5869
5869
|
return keysList.reduce(function (props, key) {
|
|
5870
5870
|
// warn if user intended a HOOK
|
|
5871
5871
|
if (key in Hook) {
|
|
5872
|
-
throw fail
|
|
5872
|
+
throw fail("Hook '" + key + "' was defined as property. Hooks should be defined as part of the actions");
|
|
5873
5873
|
}
|
|
5874
5874
|
// the user intended to use a view
|
|
5875
5875
|
var descriptor = Object.getOwnPropertyDescriptor(declaredProps, key);
|
|
5876
5876
|
if ("get" in descriptor) {
|
|
5877
|
-
throw fail
|
|
5877
|
+
throw fail("Getters are not supported as properties. Please use views instead");
|
|
5878
5878
|
}
|
|
5879
5879
|
// undefined and null are not valid
|
|
5880
5880
|
var value = descriptor.value;
|
|
5881
5881
|
if (value === null || value === undefined) {
|
|
5882
|
-
throw fail
|
|
5882
|
+
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)`?");
|
|
5883
5883
|
}
|
|
5884
5884
|
// its a primitive, convert to its type
|
|
5885
5885
|
else if (isPrimitive(value)) {
|
|
@@ -5896,14 +5896,14 @@ function toPropertiesObject(declaredProps) {
|
|
|
5896
5896
|
else if (isType(value)) ;
|
|
5897
5897
|
// its a function, maybe the user wanted a view?
|
|
5898
5898
|
else if (devMode() && typeof value === "function") {
|
|
5899
|
-
throw fail
|
|
5899
|
+
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?");
|
|
5900
5900
|
}
|
|
5901
5901
|
// no other complex values
|
|
5902
5902
|
else if (devMode() && typeof value === "object") {
|
|
5903
|
-
throw fail
|
|
5903
|
+
throw fail("Invalid type definition for property '" + key + "', it looks like you passed an object. Try passing another model type or a types.frozen.");
|
|
5904
5904
|
}
|
|
5905
5905
|
else {
|
|
5906
|
-
throw fail
|
|
5906
|
+
throw fail("Invalid type definition for property '" + key + "', cannot infer a type from a value like '" + value + "' (" + typeof value + ")");
|
|
5907
5907
|
}
|
|
5908
5908
|
return props;
|
|
5909
5909
|
}, declaredProps);
|
|
@@ -6016,7 +6016,7 @@ var ModelType = /** @class */ (function (_super) {
|
|
|
6016
6016
|
this.forAllProps(function (propName, propType) {
|
|
6017
6017
|
if (propType.flags & TypeFlags.Identifier) {
|
|
6018
6018
|
if (identifierAttribute)
|
|
6019
|
-
throw fail
|
|
6019
|
+
throw fail("Cannot define property '" + propName + "' as object identifier, property '" + identifierAttribute + "' is already defined as identifier property");
|
|
6020
6020
|
identifierAttribute = propName;
|
|
6021
6021
|
}
|
|
6022
6022
|
});
|
|
@@ -6057,15 +6057,15 @@ var ModelType = /** @class */ (function (_super) {
|
|
|
6057
6057
|
value: function (self, actions) {
|
|
6058
6058
|
// check if return is correct
|
|
6059
6059
|
if (!isPlainObject(actions))
|
|
6060
|
-
throw fail
|
|
6060
|
+
throw fail("actions initializer should return a plain object containing actions");
|
|
6061
6061
|
// bind actions to the object created
|
|
6062
6062
|
Object.keys(actions).forEach(function (name) {
|
|
6063
6063
|
// warn if preprocessor was given
|
|
6064
6064
|
if (name === PRE_PROCESS_SNAPSHOT)
|
|
6065
|
-
throw fail
|
|
6065
|
+
throw fail("Cannot define action '" + PRE_PROCESS_SNAPSHOT + "', it should be defined using 'type.preProcessSnapshot(fn)' instead");
|
|
6066
6066
|
// warn if postprocessor was given
|
|
6067
6067
|
if (name === POST_PROCESS_SNAPSHOT)
|
|
6068
|
-
throw fail
|
|
6068
|
+
throw fail("Cannot define action '" + POST_PROCESS_SNAPSHOT + "', it should be defined using 'type.postProcessSnapshot(fn)' instead");
|
|
6069
6069
|
var action2 = actions[name];
|
|
6070
6070
|
// apply hook composition
|
|
6071
6071
|
var baseAction = self[name];
|
|
@@ -6095,7 +6095,7 @@ var ModelType = /** @class */ (function (_super) {
|
|
|
6095
6095
|
value: function (fn) {
|
|
6096
6096
|
var _this = this;
|
|
6097
6097
|
if (typeof fn !== "function") {
|
|
6098
|
-
throw fail
|
|
6098
|
+
throw fail("You passed an " + typeof fn + " to volatile state as an argument, when function is expected");
|
|
6099
6099
|
}
|
|
6100
6100
|
var stateInitializer = function (self) {
|
|
6101
6101
|
_this.instantiateVolatileState(self, fn(self));
|
|
@@ -6111,7 +6111,7 @@ var ModelType = /** @class */ (function (_super) {
|
|
|
6111
6111
|
value: function (self, state) {
|
|
6112
6112
|
// check views return
|
|
6113
6113
|
if (!isPlainObject(state))
|
|
6114
|
-
throw fail
|
|
6114
|
+
throw fail("volatile state initializer should return a plain object containing state");
|
|
6115
6115
|
mobx.set(self, state);
|
|
6116
6116
|
}
|
|
6117
6117
|
});
|
|
@@ -6124,7 +6124,7 @@ var ModelType = /** @class */ (function (_super) {
|
|
|
6124
6124
|
var initializer = function (self) {
|
|
6125
6125
|
var _a = fn(self), actions = _a.actions, views = _a.views, state = _a.state, rest = __rest(_a, ["actions", "views", "state"]);
|
|
6126
6126
|
for (var key in rest)
|
|
6127
|
-
throw fail
|
|
6127
|
+
throw fail("The `extend` function should return an object with a subset of the fields 'actions', 'views' and 'state'. Found invalid key '" + key + "'");
|
|
6128
6128
|
if (state)
|
|
6129
6129
|
_this.instantiateVolatileState(self, state);
|
|
6130
6130
|
if (views)
|
|
@@ -6156,7 +6156,7 @@ var ModelType = /** @class */ (function (_super) {
|
|
|
6156
6156
|
value: function (self, views) {
|
|
6157
6157
|
// check views return
|
|
6158
6158
|
if (!isPlainObject(views))
|
|
6159
|
-
throw fail
|
|
6159
|
+
throw fail("views initializer should return a plain object containing views");
|
|
6160
6160
|
Object.getOwnPropertyNames(views).forEach(function (key) {
|
|
6161
6161
|
var _a;
|
|
6162
6162
|
// is this a computed property?
|
|
@@ -6169,7 +6169,7 @@ var ModelType = /** @class */ (function (_super) {
|
|
|
6169
6169
|
(!devMode() ? addHiddenFinalProp : addHiddenWritableProp)(self, key, descriptor.value);
|
|
6170
6170
|
}
|
|
6171
6171
|
else {
|
|
6172
|
-
throw fail
|
|
6172
|
+
throw fail("A view member should either be a function or getter based property");
|
|
6173
6173
|
}
|
|
6174
6174
|
});
|
|
6175
6175
|
}
|
|
@@ -6285,11 +6285,11 @@ var ModelType = /** @class */ (function (_super) {
|
|
|
6285
6285
|
value: function (node, key) {
|
|
6286
6286
|
var _a;
|
|
6287
6287
|
if (!(key in this.properties))
|
|
6288
|
-
throw fail
|
|
6288
|
+
throw fail("Not a value property: " + key);
|
|
6289
6289
|
var adm = mobx._getAdministration(node.storedValue, key);
|
|
6290
6290
|
var childNode = (_a = adm.raw) === null || _a === void 0 ? void 0 : _a.call(adm);
|
|
6291
6291
|
if (!childNode)
|
|
6292
|
-
throw fail
|
|
6292
|
+
throw fail("Node not available for property " + key);
|
|
6293
6293
|
return childNode;
|
|
6294
6294
|
}
|
|
6295
6295
|
});
|
|
@@ -6308,7 +6308,7 @@ var ModelType = /** @class */ (function (_super) {
|
|
|
6308
6308
|
atom.reportObserved();
|
|
6309
6309
|
}
|
|
6310
6310
|
catch (e) {
|
|
6311
|
-
throw fail
|
|
6311
|
+
throw fail(name + " property is declared twice");
|
|
6312
6312
|
}
|
|
6313
6313
|
res[name] = _this.getChildNode(node, name).snapshot;
|
|
6314
6314
|
});
|
|
@@ -6336,7 +6336,7 @@ var ModelType = /** @class */ (function (_super) {
|
|
|
6336
6336
|
writable: true,
|
|
6337
6337
|
value: function (node, subpath, patch) {
|
|
6338
6338
|
if (!(patch.op === "replace" || patch.op === "add")) {
|
|
6339
|
-
throw fail
|
|
6339
|
+
throw fail("object does not support operation " + patch.op);
|
|
6340
6340
|
}
|
|
6341
6341
|
node.storedValue[subpath] = patch.value;
|
|
6342
6342
|
}
|
|
@@ -6448,7 +6448,7 @@ function model() {
|
|
|
6448
6448
|
args[_i] = arguments[_i];
|
|
6449
6449
|
}
|
|
6450
6450
|
if (devMode() && typeof args[0] !== "string" && args[1]) {
|
|
6451
|
-
throw fail
|
|
6451
|
+
throw fail("Model creation failed. First argument must be a string when two arguments are provided");
|
|
6452
6452
|
}
|
|
6453
6453
|
var name = typeof args[0] === "string" ? args.shift() : "AnonymousModel";
|
|
6454
6454
|
var properties = args.shift() || {};
|
|
@@ -6695,7 +6695,7 @@ function getPrimitiveFactoryFromValue(value) {
|
|
|
6695
6695
|
if (value instanceof Date)
|
|
6696
6696
|
return DatePrimitive;
|
|
6697
6697
|
}
|
|
6698
|
-
throw fail
|
|
6698
|
+
throw fail("Cannot determine primitive type from value " + value);
|
|
6699
6699
|
}
|
|
6700
6700
|
/**
|
|
6701
6701
|
* Returns if a given value represents a primitive type.
|
|
@@ -7015,7 +7015,7 @@ var Union = /** @class */ (function (_super) {
|
|
|
7015
7015
|
value: function (parent, subpath, environment, initialValue) {
|
|
7016
7016
|
var type = this.determineType(initialValue, undefined);
|
|
7017
7017
|
if (!type)
|
|
7018
|
-
throw fail
|
|
7018
|
+
throw fail("No matching type for union " + this.describe()); // can happen in prod builds
|
|
7019
7019
|
return type.instantiate(parent, subpath, environment, initialValue);
|
|
7020
7020
|
}
|
|
7021
7021
|
});
|
|
@@ -7026,7 +7026,7 @@ var Union = /** @class */ (function (_super) {
|
|
|
7026
7026
|
value: function (current, newValue, parent, subpath) {
|
|
7027
7027
|
var type = this.determineType(newValue, current.getReconciliationType());
|
|
7028
7028
|
if (!type)
|
|
7029
|
-
throw fail
|
|
7029
|
+
throw fail("No matching type for union " + this.describe()); // can happen in prod builds
|
|
7030
7030
|
return type.reconcile(current, newValue, parent, subpath);
|
|
7031
7031
|
}
|
|
7032
7032
|
});
|
|
@@ -7241,7 +7241,7 @@ var OptionalValue = /** @class */ (function (_super) {
|
|
|
7241
7241
|
function checkOptionalPreconditions(type, defaultValueOrFunction) {
|
|
7242
7242
|
// make sure we never pass direct instances
|
|
7243
7243
|
if (typeof defaultValueOrFunction !== "function" && isStateTreeNode(defaultValueOrFunction)) {
|
|
7244
|
-
throw fail
|
|
7244
|
+
throw fail("default value cannot be an instance, pass a snapshot or a function that creates an instance/snapshot instead");
|
|
7245
7245
|
}
|
|
7246
7246
|
assertIsType(type, 1);
|
|
7247
7247
|
if (devMode()) {
|
|
@@ -7380,10 +7380,10 @@ var Late = /** @class */ (function (_super) {
|
|
|
7380
7380
|
throw e;
|
|
7381
7381
|
}
|
|
7382
7382
|
if (mustSucceed && t === undefined)
|
|
7383
|
-
throw fail
|
|
7383
|
+
throw fail("Late type seems to be used too early, the definition (still) returns undefined");
|
|
7384
7384
|
if (t) {
|
|
7385
7385
|
if (devMode() && !isType(t))
|
|
7386
|
-
throw fail
|
|
7386
|
+
throw fail("Failed to determine subtype, make sure types.late returns a type definition.");
|
|
7387
7387
|
this._subType = t;
|
|
7388
7388
|
}
|
|
7389
7389
|
}
|
|
@@ -7470,7 +7470,7 @@ function late(nameOrType, maybeType) {
|
|
|
7470
7470
|
// checks that the type is actually a late type
|
|
7471
7471
|
if (devMode()) {
|
|
7472
7472
|
if (!(typeof type === "function" && type.length === 0))
|
|
7473
|
-
throw fail
|
|
7473
|
+
throw fail("Invalid late type, expected a function with zero arguments that returns a type, got: " +
|
|
7474
7474
|
type);
|
|
7475
7475
|
}
|
|
7476
7476
|
return new Late(name, type);
|
|
@@ -7753,15 +7753,15 @@ var StoredReference = /** @class */ (function () {
|
|
|
7753
7753
|
else if (isStateTreeNode(value)) {
|
|
7754
7754
|
var targetNode = getStateTreeNode(value);
|
|
7755
7755
|
if (!targetNode.identifierAttribute)
|
|
7756
|
-
throw fail
|
|
7756
|
+
throw fail("Can only store references with a defined identifier attribute.");
|
|
7757
7757
|
var id = targetNode.unnormalizedIdentifier;
|
|
7758
7758
|
if (id === null || id === undefined) {
|
|
7759
|
-
throw fail
|
|
7759
|
+
throw fail("Can only store references to tree nodes with a defined identifier.");
|
|
7760
7760
|
}
|
|
7761
7761
|
this.identifier = id;
|
|
7762
7762
|
}
|
|
7763
7763
|
else {
|
|
7764
|
-
throw fail
|
|
7764
|
+
throw fail("Can only store references to tree nodes or identifiers, got: '" + value + "'");
|
|
7765
7765
|
}
|
|
7766
7766
|
}
|
|
7767
7767
|
Object.defineProperty(StoredReference.prototype, "updateResolvedReference", {
|
|
@@ -8143,7 +8143,7 @@ function reference(subType, options) {
|
|
|
8143
8143
|
if (devMode()) {
|
|
8144
8144
|
if (arguments.length === 2 && typeof arguments[1] === "string") {
|
|
8145
8145
|
// istanbul ignore next
|
|
8146
|
-
throw fail
|
|
8146
|
+
throw fail("References with base path are no longer supported. Please remove the base path.");
|
|
8147
8147
|
}
|
|
8148
8148
|
}
|
|
8149
8149
|
var getSetOptions = options ? options : undefined;
|
|
@@ -8153,7 +8153,7 @@ function reference(subType, options) {
|
|
|
8153
8153
|
if (getSetOptions && (getSetOptions.get || getSetOptions.set)) {
|
|
8154
8154
|
if (devMode()) {
|
|
8155
8155
|
if (!getSetOptions.get || !getSetOptions.set) {
|
|
8156
|
-
throw fail
|
|
8156
|
+
throw fail("reference options must either contain both a 'get' and a 'set' method or none of them");
|
|
8157
8157
|
}
|
|
8158
8158
|
}
|
|
8159
8159
|
return new CustomReferenceType(subType, {
|
|
@@ -8231,7 +8231,7 @@ var BaseIdentifierType = /** @class */ (function (_super) {
|
|
|
8231
8231
|
writable: true,
|
|
8232
8232
|
value: function (parent, subpath, environment, initialValue) {
|
|
8233
8233
|
if (!parent || !(parent.type instanceof ModelType))
|
|
8234
|
-
throw fail
|
|
8234
|
+
throw fail("Identifier types can only be instantiated as direct child of a model type");
|
|
8235
8235
|
return createScalarNode(this, parent, subpath, environment, initialValue);
|
|
8236
8236
|
}
|
|
8237
8237
|
});
|
|
@@ -8242,7 +8242,7 @@ var BaseIdentifierType = /** @class */ (function (_super) {
|
|
|
8242
8242
|
value: function (current, newValue, parent, subpath) {
|
|
8243
8243
|
// we don't consider detaching here since identifier are scalar nodes, and scalar nodes cannot be detached
|
|
8244
8244
|
if (current.storedValue !== newValue)
|
|
8245
|
-
throw fail
|
|
8245
|
+
throw fail("Tried to change identifier from '" + current.storedValue + "' to '" + newValue + "'. Changing identifiers is not allowed.");
|
|
8246
8246
|
current.setParent(parent, subpath);
|
|
8247
8247
|
return current;
|
|
8248
8248
|
}
|