mobx-state-tree 5.2.0 → 5.3.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/LICENSE +21 -0
- package/dist/mobx-state-tree.js +54 -73
- package/dist/mobx-state-tree.min.js +1 -1
- package/dist/mobx-state-tree.module.js +54 -73
- package/dist/mobx-state-tree.umd.js +54 -73
- package/dist/mobx-state-tree.umd.min.js +1 -1
- package/dist/types/complex-types/map.d.ts +4 -4
- package/package.json +118 -88
|
@@ -275,7 +275,7 @@ function recordPatches(subject, filter) {
|
|
|
275
275
|
assertIsStateTreeNode(subject, 1);
|
|
276
276
|
var data = {
|
|
277
277
|
patches: [],
|
|
278
|
-
|
|
278
|
+
inversePatches: []
|
|
279
279
|
};
|
|
280
280
|
// we will generate the immutable copy of patches on demand for public consumption
|
|
281
281
|
var publicData = {};
|
|
@@ -292,13 +292,13 @@ function recordPatches(subject, filter) {
|
|
|
292
292
|
},
|
|
293
293
|
get reversedInversePatches() {
|
|
294
294
|
if (!publicData.reversedInversePatches) {
|
|
295
|
-
publicData.reversedInversePatches = data.
|
|
295
|
+
publicData.reversedInversePatches = data.inversePatches.slice().reverse();
|
|
296
296
|
}
|
|
297
297
|
return publicData.reversedInversePatches;
|
|
298
298
|
},
|
|
299
299
|
get inversePatches() {
|
|
300
300
|
if (!publicData.inversePatches) {
|
|
301
|
-
publicData.inversePatches = data.
|
|
301
|
+
publicData.inversePatches = data.inversePatches.slice();
|
|
302
302
|
}
|
|
303
303
|
return publicData.inversePatches;
|
|
304
304
|
},
|
|
@@ -317,7 +317,7 @@ function recordPatches(subject, filter) {
|
|
|
317
317
|
return;
|
|
318
318
|
}
|
|
319
319
|
data.patches.push(patch);
|
|
320
|
-
data.
|
|
320
|
+
data.inversePatches.push(inversePatch);
|
|
321
321
|
// mark immutable public patches as dirty
|
|
322
322
|
publicData.patches = undefined;
|
|
323
323
|
publicData.inversePatches = undefined;
|
|
@@ -328,7 +328,7 @@ function recordPatches(subject, filter) {
|
|
|
328
328
|
applyPatch(target || subject, data.patches);
|
|
329
329
|
},
|
|
330
330
|
undo: function (target) {
|
|
331
|
-
applyPatch(target || subject, data.
|
|
331
|
+
applyPatch(target || subject, data.inversePatches.slice().reverse());
|
|
332
332
|
}
|
|
333
333
|
};
|
|
334
334
|
recorder.resume();
|
|
@@ -1747,9 +1747,7 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
1747
1747
|
if (!this.parent && newParent.root === this) {
|
|
1748
1748
|
throw fail$1("A state tree is not allowed to contain itself. Cannot assign " + this + " to path '" + newParent.path + "/" + subpath + "'");
|
|
1749
1749
|
}
|
|
1750
|
-
if (!this.parent &&
|
|
1751
|
-
!!this.environment &&
|
|
1752
|
-
this.environment !== newParent.root.environment) {
|
|
1750
|
+
if (!this.parent && !!this.environment && this.environment !== newParent.root.environment) {
|
|
1753
1751
|
throw fail$1("A state tree cannot be made part of another state tree as long as their environments are different.");
|
|
1754
1752
|
}
|
|
1755
1753
|
}
|
|
@@ -1773,9 +1771,7 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
1773
1771
|
value: function (name) {
|
|
1774
1772
|
var _this = this;
|
|
1775
1773
|
this.fireInternalHook(name);
|
|
1776
|
-
var fn = this.storedValue &&
|
|
1777
|
-
typeof this.storedValue === "object" &&
|
|
1778
|
-
this.storedValue[name];
|
|
1774
|
+
var fn = this.storedValue && typeof this.storedValue === "object" && this.storedValue[name];
|
|
1779
1775
|
if (typeof fn === "function") {
|
|
1780
1776
|
// we check for it to allow old mobx peer dependencies that don't have the method to work (even when still bugged)
|
|
1781
1777
|
if (_allowStateChangesInsideComputed) {
|
|
@@ -1877,8 +1873,7 @@ var ObjectNode = /** @class */ (function (_super) {
|
|
|
1877
1873
|
var actionFullPath = "";
|
|
1878
1874
|
if (actionContext && actionContext.name != null) {
|
|
1879
1875
|
// try to use the context, and if it not available use the node one
|
|
1880
|
-
var actionPath = (actionContext && actionContext.context && getPath(actionContext.context)) ||
|
|
1881
|
-
escapedPath;
|
|
1876
|
+
var actionPath = (actionContext && actionContext.context && getPath(actionContext.context)) || escapedPath;
|
|
1882
1877
|
actionFullPath = actionPath + "." + actionContext.name + "()";
|
|
1883
1878
|
}
|
|
1884
1879
|
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.";
|
|
@@ -2513,8 +2508,7 @@ var ComplexType = /** @class */ (function (_super) {
|
|
|
2513
2508
|
writable: true,
|
|
2514
2509
|
value: function (current, snapshot) {
|
|
2515
2510
|
return (!current.identifierAttribute ||
|
|
2516
|
-
current.identifier ===
|
|
2517
|
-
normalizeIdentifier(snapshot[current.identifierAttribute]));
|
|
2511
|
+
current.identifier === normalizeIdentifier(snapshot[current.identifierAttribute]));
|
|
2518
2512
|
}
|
|
2519
2513
|
});
|
|
2520
2514
|
Object.defineProperty(ComplexType.prototype, "tryToReconcileNode", {
|
|
@@ -2827,11 +2821,11 @@ var RunningAction = /** @class */ (function () {
|
|
|
2827
2821
|
* @returns
|
|
2828
2822
|
*/
|
|
2829
2823
|
function createActionTrackingMiddleware2(middlewareHooks) {
|
|
2830
|
-
var runningActions = new
|
|
2824
|
+
var runningActions = new Map();
|
|
2831
2825
|
return function actionTrackingMiddleware(call, next) {
|
|
2832
2826
|
// find parentRunningAction
|
|
2833
2827
|
var parentRunningAction = call.parentActionEvent
|
|
2834
|
-
? runningActions.get(call.parentActionEvent)
|
|
2828
|
+
? runningActions.get(call.parentActionEvent.id)
|
|
2835
2829
|
: undefined;
|
|
2836
2830
|
if (call.type === "action") {
|
|
2837
2831
|
var newCall = __assign(__assign({}, call), {
|
|
@@ -2840,17 +2834,19 @@ function createActionTrackingMiddleware2(middlewareHooks) {
|
|
|
2840
2834
|
var passesFilter = !middlewareHooks.filter || middlewareHooks.filter(newCall);
|
|
2841
2835
|
var hooks = passesFilter ? middlewareHooks : undefined;
|
|
2842
2836
|
var runningAction = new RunningAction(hooks, newCall);
|
|
2843
|
-
runningActions.set(call, runningAction);
|
|
2837
|
+
runningActions.set(call.id, runningAction);
|
|
2844
2838
|
var res = void 0;
|
|
2845
2839
|
try {
|
|
2846
2840
|
res = next(call);
|
|
2847
2841
|
}
|
|
2848
2842
|
catch (e) {
|
|
2843
|
+
runningActions.delete(call.id);
|
|
2849
2844
|
runningAction.finish(e);
|
|
2850
2845
|
throw e;
|
|
2851
2846
|
}
|
|
2847
|
+
// sync action finished
|
|
2852
2848
|
if (!runningAction.hasFlowsPending) {
|
|
2853
|
-
|
|
2849
|
+
runningActions.delete(call.id);
|
|
2854
2850
|
runningAction.finish();
|
|
2855
2851
|
}
|
|
2856
2852
|
return res;
|
|
@@ -2876,6 +2872,7 @@ function createActionTrackingMiddleware2(middlewareHooks) {
|
|
|
2876
2872
|
finally {
|
|
2877
2873
|
parentRunningAction.decFlowsPending();
|
|
2878
2874
|
if (!parentRunningAction.hasFlowsPending) {
|
|
2875
|
+
runningActions.delete(call.parentActionEvent.id);
|
|
2879
2876
|
parentRunningAction.finish(error);
|
|
2880
2877
|
}
|
|
2881
2878
|
}
|
|
@@ -2887,6 +2884,7 @@ function createActionTrackingMiddleware2(middlewareHooks) {
|
|
|
2887
2884
|
finally {
|
|
2888
2885
|
parentRunningAction.decFlowsPending();
|
|
2889
2886
|
if (!parentRunningAction.hasFlowsPending) {
|
|
2887
|
+
runningActions.delete(call.parentActionEvent.id);
|
|
2890
2888
|
parentRunningAction.finish();
|
|
2891
2889
|
}
|
|
2892
2890
|
}
|
|
@@ -2908,8 +2906,7 @@ function serializeArgument(node, actionName, index, arg) {
|
|
|
2908
2906
|
if (typeof arg === "function")
|
|
2909
2907
|
return serializeTheUnserializable("[function]");
|
|
2910
2908
|
if (typeof arg === "object" && !isPlainObject(arg) && !isArray(arg))
|
|
2911
|
-
return serializeTheUnserializable("[object " + ((arg && arg.constructor && arg.constructor.name) ||
|
|
2912
|
-
"Complex Object") + "]");
|
|
2909
|
+
return serializeTheUnserializable("[object " + ((arg && arg.constructor && arg.constructor.name) || "Complex Object") + "]");
|
|
2913
2910
|
try {
|
|
2914
2911
|
// Check if serializable, cycle free etc...
|
|
2915
2912
|
// MWE: there must be a better way....
|
|
@@ -3165,8 +3162,7 @@ function createActionInvoker(target, name, fn) {
|
|
|
3165
3162
|
tree: getRoot(target),
|
|
3166
3163
|
rootId: parentContext ? parentContext.rootId : id,
|
|
3167
3164
|
parentId: parentContext ? parentContext.id : 0,
|
|
3168
|
-
allParentIds: parentContext
|
|
3169
|
-
? __spread(parentContext.allParentIds, [parentContext.id]) : [],
|
|
3165
|
+
allParentIds: parentContext ? __spread(parentContext.allParentIds, [parentContext.id]) : [],
|
|
3170
3166
|
parentEvent: parentContext,
|
|
3171
3167
|
parentActionEvent: parentActionContext
|
|
3172
3168
|
}, fn);
|
|
@@ -3760,7 +3756,7 @@ function getRelativePathBetweenNodes(base, target) {
|
|
|
3760
3756
|
break;
|
|
3761
3757
|
}
|
|
3762
3758
|
// TODO: assert that no targetParts paths are "..", "." or ""!
|
|
3763
|
-
return
|
|
3759
|
+
return baseParts.slice(common).map(doubleDot).join("/") + joinJsonPath(targetParts.slice(common));
|
|
3764
3760
|
}
|
|
3765
3761
|
/**
|
|
3766
3762
|
* @internal
|
|
@@ -3777,47 +3773,44 @@ function resolveNodeByPath(base, path, failIfResolveFails) {
|
|
|
3777
3773
|
function resolveNodeByPathParts(base, pathParts, failIfResolveFails) {
|
|
3778
3774
|
if (failIfResolveFails === void 0) { failIfResolveFails = true; }
|
|
3779
3775
|
var current = base;
|
|
3780
|
-
|
|
3781
|
-
var
|
|
3782
|
-
|
|
3783
|
-
|
|
3784
|
-
|
|
3785
|
-
|
|
3786
|
-
|
|
3787
|
-
|
|
3788
|
-
|
|
3789
|
-
|
|
3790
|
-
|
|
3791
|
-
if (current
|
|
3792
|
-
|
|
3793
|
-
|
|
3794
|
-
|
|
3776
|
+
try {
|
|
3777
|
+
for (var i = 0; i < pathParts.length; i++) {
|
|
3778
|
+
var part = pathParts[i];
|
|
3779
|
+
if (part === "..") {
|
|
3780
|
+
current = current.parent;
|
|
3781
|
+
if (current)
|
|
3782
|
+
continue; // not everything has a parent
|
|
3783
|
+
}
|
|
3784
|
+
else if (part === ".") {
|
|
3785
|
+
continue;
|
|
3786
|
+
}
|
|
3787
|
+
else if (current) {
|
|
3788
|
+
if (current instanceof ScalarNode) {
|
|
3789
|
+
// check if the value of a scalar resolves to a state tree node (e.g. references)
|
|
3790
|
+
// then we can continue resolving...
|
|
3795
3791
|
var value = current.value;
|
|
3796
3792
|
if (isStateTreeNode(value)) {
|
|
3797
3793
|
current = getStateTreeNode(value);
|
|
3798
3794
|
// fall through
|
|
3799
3795
|
}
|
|
3800
3796
|
}
|
|
3801
|
-
|
|
3802
|
-
|
|
3803
|
-
|
|
3797
|
+
if (current instanceof ObjectNode) {
|
|
3798
|
+
var subType = current.getChildType(part);
|
|
3799
|
+
if (subType) {
|
|
3800
|
+
current = current.getChildNode(part);
|
|
3801
|
+
if (current)
|
|
3802
|
+
continue;
|
|
3804
3803
|
}
|
|
3805
|
-
throw e;
|
|
3806
3804
|
}
|
|
3807
3805
|
}
|
|
3808
|
-
if (current instanceof ObjectNode) {
|
|
3809
|
-
var subType = current.getChildType(part);
|
|
3810
|
-
if (subType) {
|
|
3811
|
-
current = current.getChildNode(part);
|
|
3812
|
-
if (current)
|
|
3813
|
-
continue;
|
|
3814
|
-
}
|
|
3815
|
-
}
|
|
3816
|
-
}
|
|
3817
|
-
if (failIfResolveFails)
|
|
3818
3806
|
throw fail$1("Could not resolve '" + part + "' in path '" + (joinJsonPath(pathParts.slice(0, i)) || "/") + "' while resolving '" + joinJsonPath(pathParts) + "'");
|
|
3819
|
-
|
|
3807
|
+
}
|
|
3808
|
+
}
|
|
3809
|
+
catch (e) {
|
|
3810
|
+
if (!failIfResolveFails) {
|
|
3820
3811
|
return undefined;
|
|
3812
|
+
}
|
|
3813
|
+
throw e;
|
|
3821
3814
|
}
|
|
3822
3815
|
return current;
|
|
3823
3816
|
}
|
|
@@ -4007,8 +4000,7 @@ function deepFreeze(value) {
|
|
|
4007
4000
|
freeze(value);
|
|
4008
4001
|
if (isPlainObject(value)) {
|
|
4009
4002
|
Object.keys(value).forEach(function (propKey) {
|
|
4010
|
-
if (!isPrimitive(value[propKey]) &&
|
|
4011
|
-
!Object.isFrozen(value[propKey])) {
|
|
4003
|
+
if (!isPrimitive(value[propKey]) && !Object.isFrozen(value[propKey])) {
|
|
4012
4004
|
deepFreeze(value[propKey]);
|
|
4013
4005
|
}
|
|
4014
4006
|
});
|
|
@@ -6414,9 +6406,7 @@ var ModelType = /** @class */ (function (_super) {
|
|
|
6414
6406
|
var _this = this;
|
|
6415
6407
|
// optimization: cache
|
|
6416
6408
|
return ("{ " +
|
|
6417
|
-
this.propertyNames
|
|
6418
|
-
.map(function (key) { return key + ": " + _this.properties[key].describe(); })
|
|
6419
|
-
.join("; ") +
|
|
6409
|
+
this.propertyNames.map(function (key) { return key + ": " + _this.properties[key].describe(); }).join("; ") +
|
|
6420
6410
|
" }");
|
|
6421
6411
|
}
|
|
6422
6412
|
});
|
|
@@ -6904,9 +6894,7 @@ function refinement() {
|
|
|
6904
6894
|
var name = typeof args[0] === "string" ? args.shift() : isType(args[0]) ? args[0].name : null;
|
|
6905
6895
|
var type = args[0];
|
|
6906
6896
|
var predicate = args[1];
|
|
6907
|
-
var message = args[2]
|
|
6908
|
-
? args[2]
|
|
6909
|
-
: function (v) { return "Value does not respect the refinement predicate"; };
|
|
6897
|
+
var message = args[2] ? args[2] : function (v) { return "Value does not respect the refinement predicate"; };
|
|
6910
6898
|
// ensures all parameters are correct
|
|
6911
6899
|
assertIsType(type, [1, 2]);
|
|
6912
6900
|
assertIsString(name, 1);
|
|
@@ -7049,9 +7037,7 @@ var Union = /** @class */ (function (_super) {
|
|
|
7049
7037
|
if (reconcileCurrentType.is(value)) {
|
|
7050
7038
|
return reconcileCurrentType;
|
|
7051
7039
|
}
|
|
7052
|
-
return this._types
|
|
7053
|
-
.filter(function (t) { return t !== reconcileCurrentType; })
|
|
7054
|
-
.find(function (type) { return type.is(value); });
|
|
7040
|
+
return this._types.filter(function (t) { return t !== reconcileCurrentType; }).find(function (type) { return type.is(value); });
|
|
7055
7041
|
}
|
|
7056
7042
|
else {
|
|
7057
7043
|
return this._types.find(function (type) { return type.is(value); });
|
|
@@ -7530,8 +7516,7 @@ var Lazy = /** @class */ (function (_super) {
|
|
|
7530
7516
|
when(function () {
|
|
7531
7517
|
return _this.pendingNodeList.length > 0 &&
|
|
7532
7518
|
_this.pendingNodeList.some(function (node) {
|
|
7533
|
-
return node.isAlive &&
|
|
7534
|
-
_this.options.shouldLoadPredicate(node.parent ? node.parent.value : null);
|
|
7519
|
+
return node.isAlive && _this.options.shouldLoadPredicate(node.parent ? node.parent.value : null);
|
|
7535
7520
|
});
|
|
7536
7521
|
}, function () {
|
|
7537
7522
|
_this.options.loadType().then(action(function (type) {
|
|
@@ -8045,9 +8030,7 @@ var IdentifierReferenceType = /** @class */ (function (_super) {
|
|
|
8045
8030
|
configurable: true,
|
|
8046
8031
|
writable: true,
|
|
8047
8032
|
value: function (parent, subpath, environment, initialValue) {
|
|
8048
|
-
var identifier = isStateTreeNode(initialValue)
|
|
8049
|
-
? getIdentifier(initialValue)
|
|
8050
|
-
: initialValue;
|
|
8033
|
+
var identifier = isStateTreeNode(initialValue) ? getIdentifier(initialValue) : initialValue;
|
|
8051
8034
|
var storedRef = new StoredReference(initialValue, this.targetType);
|
|
8052
8035
|
var storedRefNode = createScalarNode(this, parent, subpath, environment, storedRef);
|
|
8053
8036
|
storedRef.node = storedRefNode;
|
|
@@ -8132,9 +8115,7 @@ var CustomReferenceType = /** @class */ (function (_super) {
|
|
|
8132
8115
|
var newIdentifier = isStateTreeNode(newValue)
|
|
8133
8116
|
? this.options.set(newValue, current ? current.storedValue : null)
|
|
8134
8117
|
: newValue;
|
|
8135
|
-
if (!current.isDetaching &&
|
|
8136
|
-
current.type === this &&
|
|
8137
|
-
current.storedValue === newIdentifier) {
|
|
8118
|
+
if (!current.isDetaching && current.type === this && current.storedValue === newIdentifier) {
|
|
8138
8119
|
current.setParent(parent, subpath);
|
|
8139
8120
|
return current;
|
|
8140
8121
|
}
|
|
@@ -279,7 +279,7 @@
|
|
|
279
279
|
assertIsStateTreeNode(subject, 1);
|
|
280
280
|
var data = {
|
|
281
281
|
patches: [],
|
|
282
|
-
|
|
282
|
+
inversePatches: []
|
|
283
283
|
};
|
|
284
284
|
// we will generate the immutable copy of patches on demand for public consumption
|
|
285
285
|
var publicData = {};
|
|
@@ -296,13 +296,13 @@
|
|
|
296
296
|
},
|
|
297
297
|
get reversedInversePatches() {
|
|
298
298
|
if (!publicData.reversedInversePatches) {
|
|
299
|
-
publicData.reversedInversePatches = data.
|
|
299
|
+
publicData.reversedInversePatches = data.inversePatches.slice().reverse();
|
|
300
300
|
}
|
|
301
301
|
return publicData.reversedInversePatches;
|
|
302
302
|
},
|
|
303
303
|
get inversePatches() {
|
|
304
304
|
if (!publicData.inversePatches) {
|
|
305
|
-
publicData.inversePatches = data.
|
|
305
|
+
publicData.inversePatches = data.inversePatches.slice();
|
|
306
306
|
}
|
|
307
307
|
return publicData.inversePatches;
|
|
308
308
|
},
|
|
@@ -321,7 +321,7 @@
|
|
|
321
321
|
return;
|
|
322
322
|
}
|
|
323
323
|
data.patches.push(patch);
|
|
324
|
-
data.
|
|
324
|
+
data.inversePatches.push(inversePatch);
|
|
325
325
|
// mark immutable public patches as dirty
|
|
326
326
|
publicData.patches = undefined;
|
|
327
327
|
publicData.inversePatches = undefined;
|
|
@@ -332,7 +332,7 @@
|
|
|
332
332
|
applyPatch(target || subject, data.patches);
|
|
333
333
|
},
|
|
334
334
|
undo: function (target) {
|
|
335
|
-
applyPatch(target || subject, data.
|
|
335
|
+
applyPatch(target || subject, data.inversePatches.slice().reverse());
|
|
336
336
|
}
|
|
337
337
|
};
|
|
338
338
|
recorder.resume();
|
|
@@ -1751,9 +1751,7 @@
|
|
|
1751
1751
|
if (!this.parent && newParent.root === this) {
|
|
1752
1752
|
throw fail$1("A state tree is not allowed to contain itself. Cannot assign " + this + " to path '" + newParent.path + "/" + subpath + "'");
|
|
1753
1753
|
}
|
|
1754
|
-
if (!this.parent &&
|
|
1755
|
-
!!this.environment &&
|
|
1756
|
-
this.environment !== newParent.root.environment) {
|
|
1754
|
+
if (!this.parent && !!this.environment && this.environment !== newParent.root.environment) {
|
|
1757
1755
|
throw fail$1("A state tree cannot be made part of another state tree as long as their environments are different.");
|
|
1758
1756
|
}
|
|
1759
1757
|
}
|
|
@@ -1777,9 +1775,7 @@
|
|
|
1777
1775
|
value: function (name) {
|
|
1778
1776
|
var _this = this;
|
|
1779
1777
|
this.fireInternalHook(name);
|
|
1780
|
-
var fn = this.storedValue &&
|
|
1781
|
-
typeof this.storedValue === "object" &&
|
|
1782
|
-
this.storedValue[name];
|
|
1778
|
+
var fn = this.storedValue && typeof this.storedValue === "object" && this.storedValue[name];
|
|
1783
1779
|
if (typeof fn === "function") {
|
|
1784
1780
|
// we check for it to allow old mobx peer dependencies that don't have the method to work (even when still bugged)
|
|
1785
1781
|
if (mobx._allowStateChangesInsideComputed) {
|
|
@@ -1881,8 +1877,7 @@
|
|
|
1881
1877
|
var actionFullPath = "";
|
|
1882
1878
|
if (actionContext && actionContext.name != null) {
|
|
1883
1879
|
// try to use the context, and if it not available use the node one
|
|
1884
|
-
var actionPath = (actionContext && actionContext.context && getPath(actionContext.context)) ||
|
|
1885
|
-
escapedPath;
|
|
1880
|
+
var actionPath = (actionContext && actionContext.context && getPath(actionContext.context)) || escapedPath;
|
|
1886
1881
|
actionFullPath = actionPath + "." + actionContext.name + "()";
|
|
1887
1882
|
}
|
|
1888
1883
|
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.";
|
|
@@ -2517,8 +2512,7 @@
|
|
|
2517
2512
|
writable: true,
|
|
2518
2513
|
value: function (current, snapshot) {
|
|
2519
2514
|
return (!current.identifierAttribute ||
|
|
2520
|
-
current.identifier ===
|
|
2521
|
-
normalizeIdentifier(snapshot[current.identifierAttribute]));
|
|
2515
|
+
current.identifier === normalizeIdentifier(snapshot[current.identifierAttribute]));
|
|
2522
2516
|
}
|
|
2523
2517
|
});
|
|
2524
2518
|
Object.defineProperty(ComplexType.prototype, "tryToReconcileNode", {
|
|
@@ -2831,11 +2825,11 @@
|
|
|
2831
2825
|
* @returns
|
|
2832
2826
|
*/
|
|
2833
2827
|
function createActionTrackingMiddleware2(middlewareHooks) {
|
|
2834
|
-
var runningActions = new
|
|
2828
|
+
var runningActions = new Map();
|
|
2835
2829
|
return function actionTrackingMiddleware(call, next) {
|
|
2836
2830
|
// find parentRunningAction
|
|
2837
2831
|
var parentRunningAction = call.parentActionEvent
|
|
2838
|
-
? runningActions.get(call.parentActionEvent)
|
|
2832
|
+
? runningActions.get(call.parentActionEvent.id)
|
|
2839
2833
|
: undefined;
|
|
2840
2834
|
if (call.type === "action") {
|
|
2841
2835
|
var newCall = __assign(__assign({}, call), {
|
|
@@ -2844,17 +2838,19 @@
|
|
|
2844
2838
|
var passesFilter = !middlewareHooks.filter || middlewareHooks.filter(newCall);
|
|
2845
2839
|
var hooks = passesFilter ? middlewareHooks : undefined;
|
|
2846
2840
|
var runningAction = new RunningAction(hooks, newCall);
|
|
2847
|
-
runningActions.set(call, runningAction);
|
|
2841
|
+
runningActions.set(call.id, runningAction);
|
|
2848
2842
|
var res = void 0;
|
|
2849
2843
|
try {
|
|
2850
2844
|
res = next(call);
|
|
2851
2845
|
}
|
|
2852
2846
|
catch (e) {
|
|
2847
|
+
runningActions.delete(call.id);
|
|
2853
2848
|
runningAction.finish(e);
|
|
2854
2849
|
throw e;
|
|
2855
2850
|
}
|
|
2851
|
+
// sync action finished
|
|
2856
2852
|
if (!runningAction.hasFlowsPending) {
|
|
2857
|
-
|
|
2853
|
+
runningActions.delete(call.id);
|
|
2858
2854
|
runningAction.finish();
|
|
2859
2855
|
}
|
|
2860
2856
|
return res;
|
|
@@ -2880,6 +2876,7 @@
|
|
|
2880
2876
|
finally {
|
|
2881
2877
|
parentRunningAction.decFlowsPending();
|
|
2882
2878
|
if (!parentRunningAction.hasFlowsPending) {
|
|
2879
|
+
runningActions.delete(call.parentActionEvent.id);
|
|
2883
2880
|
parentRunningAction.finish(error);
|
|
2884
2881
|
}
|
|
2885
2882
|
}
|
|
@@ -2891,6 +2888,7 @@
|
|
|
2891
2888
|
finally {
|
|
2892
2889
|
parentRunningAction.decFlowsPending();
|
|
2893
2890
|
if (!parentRunningAction.hasFlowsPending) {
|
|
2891
|
+
runningActions.delete(call.parentActionEvent.id);
|
|
2894
2892
|
parentRunningAction.finish();
|
|
2895
2893
|
}
|
|
2896
2894
|
}
|
|
@@ -2912,8 +2910,7 @@
|
|
|
2912
2910
|
if (typeof arg === "function")
|
|
2913
2911
|
return serializeTheUnserializable("[function]");
|
|
2914
2912
|
if (typeof arg === "object" && !isPlainObject(arg) && !isArray(arg))
|
|
2915
|
-
return serializeTheUnserializable("[object " + ((arg && arg.constructor && arg.constructor.name) ||
|
|
2916
|
-
"Complex Object") + "]");
|
|
2913
|
+
return serializeTheUnserializable("[object " + ((arg && arg.constructor && arg.constructor.name) || "Complex Object") + "]");
|
|
2917
2914
|
try {
|
|
2918
2915
|
// Check if serializable, cycle free etc...
|
|
2919
2916
|
// MWE: there must be a better way....
|
|
@@ -3169,8 +3166,7 @@
|
|
|
3169
3166
|
tree: getRoot(target),
|
|
3170
3167
|
rootId: parentContext ? parentContext.rootId : id,
|
|
3171
3168
|
parentId: parentContext ? parentContext.id : 0,
|
|
3172
|
-
allParentIds: parentContext
|
|
3173
|
-
? __spread(parentContext.allParentIds, [parentContext.id]) : [],
|
|
3169
|
+
allParentIds: parentContext ? __spread(parentContext.allParentIds, [parentContext.id]) : [],
|
|
3174
3170
|
parentEvent: parentContext,
|
|
3175
3171
|
parentActionEvent: parentActionContext
|
|
3176
3172
|
}, fn);
|
|
@@ -3764,7 +3760,7 @@
|
|
|
3764
3760
|
break;
|
|
3765
3761
|
}
|
|
3766
3762
|
// TODO: assert that no targetParts paths are "..", "." or ""!
|
|
3767
|
-
return
|
|
3763
|
+
return baseParts.slice(common).map(doubleDot).join("/") + joinJsonPath(targetParts.slice(common));
|
|
3768
3764
|
}
|
|
3769
3765
|
/**
|
|
3770
3766
|
* @internal
|
|
@@ -3781,47 +3777,44 @@
|
|
|
3781
3777
|
function resolveNodeByPathParts(base, pathParts, failIfResolveFails) {
|
|
3782
3778
|
if (failIfResolveFails === void 0) { failIfResolveFails = true; }
|
|
3783
3779
|
var current = base;
|
|
3784
|
-
|
|
3785
|
-
var
|
|
3786
|
-
|
|
3787
|
-
|
|
3788
|
-
|
|
3789
|
-
|
|
3790
|
-
|
|
3791
|
-
|
|
3792
|
-
|
|
3793
|
-
|
|
3794
|
-
|
|
3795
|
-
if (current
|
|
3796
|
-
|
|
3797
|
-
|
|
3798
|
-
|
|
3780
|
+
try {
|
|
3781
|
+
for (var i = 0; i < pathParts.length; i++) {
|
|
3782
|
+
var part = pathParts[i];
|
|
3783
|
+
if (part === "..") {
|
|
3784
|
+
current = current.parent;
|
|
3785
|
+
if (current)
|
|
3786
|
+
continue; // not everything has a parent
|
|
3787
|
+
}
|
|
3788
|
+
else if (part === ".") {
|
|
3789
|
+
continue;
|
|
3790
|
+
}
|
|
3791
|
+
else if (current) {
|
|
3792
|
+
if (current instanceof ScalarNode) {
|
|
3793
|
+
// check if the value of a scalar resolves to a state tree node (e.g. references)
|
|
3794
|
+
// then we can continue resolving...
|
|
3799
3795
|
var value = current.value;
|
|
3800
3796
|
if (isStateTreeNode(value)) {
|
|
3801
3797
|
current = getStateTreeNode(value);
|
|
3802
3798
|
// fall through
|
|
3803
3799
|
}
|
|
3804
3800
|
}
|
|
3805
|
-
|
|
3806
|
-
|
|
3807
|
-
|
|
3801
|
+
if (current instanceof ObjectNode) {
|
|
3802
|
+
var subType = current.getChildType(part);
|
|
3803
|
+
if (subType) {
|
|
3804
|
+
current = current.getChildNode(part);
|
|
3805
|
+
if (current)
|
|
3806
|
+
continue;
|
|
3808
3807
|
}
|
|
3809
|
-
throw e;
|
|
3810
3808
|
}
|
|
3811
3809
|
}
|
|
3812
|
-
if (current instanceof ObjectNode) {
|
|
3813
|
-
var subType = current.getChildType(part);
|
|
3814
|
-
if (subType) {
|
|
3815
|
-
current = current.getChildNode(part);
|
|
3816
|
-
if (current)
|
|
3817
|
-
continue;
|
|
3818
|
-
}
|
|
3819
|
-
}
|
|
3820
|
-
}
|
|
3821
|
-
if (failIfResolveFails)
|
|
3822
3810
|
throw fail$1("Could not resolve '" + part + "' in path '" + (joinJsonPath(pathParts.slice(0, i)) || "/") + "' while resolving '" + joinJsonPath(pathParts) + "'");
|
|
3823
|
-
|
|
3811
|
+
}
|
|
3812
|
+
}
|
|
3813
|
+
catch (e) {
|
|
3814
|
+
if (!failIfResolveFails) {
|
|
3824
3815
|
return undefined;
|
|
3816
|
+
}
|
|
3817
|
+
throw e;
|
|
3825
3818
|
}
|
|
3826
3819
|
return current;
|
|
3827
3820
|
}
|
|
@@ -4007,8 +4000,7 @@
|
|
|
4007
4000
|
freeze(value);
|
|
4008
4001
|
if (isPlainObject(value)) {
|
|
4009
4002
|
Object.keys(value).forEach(function (propKey) {
|
|
4010
|
-
if (!isPrimitive(value[propKey]) &&
|
|
4011
|
-
!Object.isFrozen(value[propKey])) {
|
|
4003
|
+
if (!isPrimitive(value[propKey]) && !Object.isFrozen(value[propKey])) {
|
|
4012
4004
|
deepFreeze(value[propKey]);
|
|
4013
4005
|
}
|
|
4014
4006
|
});
|
|
@@ -6396,9 +6388,7 @@
|
|
|
6396
6388
|
var _this = this;
|
|
6397
6389
|
// optimization: cache
|
|
6398
6390
|
return ("{ " +
|
|
6399
|
-
this.propertyNames
|
|
6400
|
-
.map(function (key) { return key + ": " + _this.properties[key].describe(); })
|
|
6401
|
-
.join("; ") +
|
|
6391
|
+
this.propertyNames.map(function (key) { return key + ": " + _this.properties[key].describe(); }).join("; ") +
|
|
6402
6392
|
" }");
|
|
6403
6393
|
}
|
|
6404
6394
|
});
|
|
@@ -6886,9 +6876,7 @@
|
|
|
6886
6876
|
var name = typeof args[0] === "string" ? args.shift() : isType(args[0]) ? args[0].name : null;
|
|
6887
6877
|
var type = args[0];
|
|
6888
6878
|
var predicate = args[1];
|
|
6889
|
-
var message = args[2]
|
|
6890
|
-
? args[2]
|
|
6891
|
-
: function (v) { return "Value does not respect the refinement predicate"; };
|
|
6879
|
+
var message = args[2] ? args[2] : function (v) { return "Value does not respect the refinement predicate"; };
|
|
6892
6880
|
// ensures all parameters are correct
|
|
6893
6881
|
assertIsType(type, [1, 2]);
|
|
6894
6882
|
assertIsString(name, 1);
|
|
@@ -7031,9 +7019,7 @@
|
|
|
7031
7019
|
if (reconcileCurrentType.is(value)) {
|
|
7032
7020
|
return reconcileCurrentType;
|
|
7033
7021
|
}
|
|
7034
|
-
return this._types
|
|
7035
|
-
.filter(function (t) { return t !== reconcileCurrentType; })
|
|
7036
|
-
.find(function (type) { return type.is(value); });
|
|
7022
|
+
return this._types.filter(function (t) { return t !== reconcileCurrentType; }).find(function (type) { return type.is(value); });
|
|
7037
7023
|
}
|
|
7038
7024
|
else {
|
|
7039
7025
|
return this._types.find(function (type) { return type.is(value); });
|
|
@@ -7512,8 +7498,7 @@
|
|
|
7512
7498
|
mobx.when(function () {
|
|
7513
7499
|
return _this.pendingNodeList.length > 0 &&
|
|
7514
7500
|
_this.pendingNodeList.some(function (node) {
|
|
7515
|
-
return node.isAlive &&
|
|
7516
|
-
_this.options.shouldLoadPredicate(node.parent ? node.parent.value : null);
|
|
7501
|
+
return node.isAlive && _this.options.shouldLoadPredicate(node.parent ? node.parent.value : null);
|
|
7517
7502
|
});
|
|
7518
7503
|
}, function () {
|
|
7519
7504
|
_this.options.loadType().then(mobx.action(function (type) {
|
|
@@ -8027,9 +8012,7 @@
|
|
|
8027
8012
|
configurable: true,
|
|
8028
8013
|
writable: true,
|
|
8029
8014
|
value: function (parent, subpath, environment, initialValue) {
|
|
8030
|
-
var identifier = isStateTreeNode(initialValue)
|
|
8031
|
-
? getIdentifier(initialValue)
|
|
8032
|
-
: initialValue;
|
|
8015
|
+
var identifier = isStateTreeNode(initialValue) ? getIdentifier(initialValue) : initialValue;
|
|
8033
8016
|
var storedRef = new StoredReference(initialValue, this.targetType);
|
|
8034
8017
|
var storedRefNode = createScalarNode(this, parent, subpath, environment, storedRef);
|
|
8035
8018
|
storedRef.node = storedRefNode;
|
|
@@ -8114,9 +8097,7 @@
|
|
|
8114
8097
|
var newIdentifier = isStateTreeNode(newValue)
|
|
8115
8098
|
? this.options.set(newValue, current ? current.storedValue : null)
|
|
8116
8099
|
: newValue;
|
|
8117
|
-
if (!current.isDetaching &&
|
|
8118
|
-
current.type === this &&
|
|
8119
|
-
current.storedValue === newIdentifier) {
|
|
8100
|
+
if (!current.isDetaching && current.type === this && current.storedValue === newIdentifier) {
|
|
8120
8101
|
current.setParent(parent, subpath);
|
|
8121
8102
|
return current;
|
|
8122
8103
|
}
|