mobx-state-tree 7.3.1 → 7.3.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/mobx-state-tree.js
CHANGED
|
@@ -6033,6 +6033,7 @@ var ArrayType = /** @class */ (function (_super) {
|
|
|
6033
6033
|
configurable: true,
|
|
6034
6034
|
writable: true,
|
|
6035
6035
|
value: function (node, snapshot) {
|
|
6036
|
+
var e_1, _a;
|
|
6036
6037
|
if (!isArray(snapshot)) {
|
|
6037
6038
|
typecheckInternal(this, snapshot);
|
|
6038
6039
|
return;
|
|
@@ -6061,24 +6062,32 @@ var ArrayType = /** @class */ (function (_super) {
|
|
|
6061
6062
|
applyDirectSnapshotsInRange(childNodes, snapshot, firstChangedIndex);
|
|
6062
6063
|
return;
|
|
6063
6064
|
}
|
|
6064
|
-
|
|
6065
|
-
|
|
6066
|
-
|
|
6067
|
-
|
|
6068
|
-
|
|
6069
|
-
|
|
6070
|
-
|
|
6071
|
-
|
|
6072
|
-
|
|
6073
|
-
|
|
6074
|
-
|
|
6075
|
-
|
|
6076
|
-
|
|
6077
|
-
|
|
6078
|
-
|
|
6079
|
-
|
|
6065
|
+
// The lengths match, so only the differing entries have to change. Collect them
|
|
6066
|
+
// before touching the array, because assigning to one entry invalidates the
|
|
6067
|
+
// snapshots of the others and their identity can no longer be compared.
|
|
6068
|
+
var changedIndexes = [];
|
|
6069
|
+
for (var i = firstChangedIndex; i < oldLength; i++) {
|
|
6070
|
+
if (childNodes[i].snapshot !== snapshot[i]) {
|
|
6071
|
+
changedIndexes.push(i);
|
|
6072
|
+
}
|
|
6073
|
+
}
|
|
6074
|
+
try {
|
|
6075
|
+
// Assign the changed entries individually rather than splicing across the
|
|
6076
|
+
// untouched entries between them: a single assignment reconciles exactly one
|
|
6077
|
+
// child, which keeps the cost proportional to the number of changes instead of
|
|
6078
|
+
// the distance between the first and the last of them.
|
|
6079
|
+
for (var changedIndexes_1 = __values(changedIndexes), changedIndexes_1_1 = changedIndexes_1.next(); !changedIndexes_1_1.done; changedIndexes_1_1 = changedIndexes_1.next()) {
|
|
6080
|
+
var index = changedIndexes_1_1.value;
|
|
6081
|
+
target[index] = snapshot[index];
|
|
6082
|
+
}
|
|
6083
|
+
}
|
|
6084
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
6085
|
+
finally {
|
|
6086
|
+
try {
|
|
6087
|
+
if (changedIndexes_1_1 && !changedIndexes_1_1.done && (_a = changedIndexes_1.return)) _a.call(changedIndexes_1);
|
|
6088
|
+
}
|
|
6089
|
+
finally { if (e_1) throw e_1.error; }
|
|
6080
6090
|
}
|
|
6081
|
-
target.splice.apply(target, __spreadArray([firstChangedIndex, replacedCount], __read(replacementSnapshots), false));
|
|
6082
6091
|
}
|
|
6083
6092
|
});
|
|
6084
6093
|
Object.defineProperty(ArrayType.prototype, "getChildType", {
|
|
@@ -6159,9 +6168,17 @@ function findFirstChangedIndex(childNodes, snapshot, length) {
|
|
|
6159
6168
|
}
|
|
6160
6169
|
function canApplyDirectSnapshotsInRange(childType, childNodes, snapshot, startIndex) {
|
|
6161
6170
|
for (var i = startIndex; i < childNodes.length; i++) {
|
|
6162
|
-
|
|
6171
|
+
var childNode = childNodes[i];
|
|
6172
|
+
if (childNode.snapshot === snapshot[i])
|
|
6163
6173
|
continue;
|
|
6164
|
-
if (!canApplyDirectSnapshot(childType,
|
|
6174
|
+
if (!canApplyDirectSnapshot(childType, childNode, snapshot[i])) {
|
|
6175
|
+
return false;
|
|
6176
|
+
}
|
|
6177
|
+
// Array reconciliation only treats two snapshots as the same child when they carry
|
|
6178
|
+
// a matching identifier (see `areSame`). Identifier-less children are replaced
|
|
6179
|
+
// rather than updated in place, so they must not take the direct-apply path or
|
|
6180
|
+
// lifecycle hooks such as afterCreate would never run for the new child.
|
|
6181
|
+
if (!childNode.identifierAttribute || childNode.identifier === null) {
|
|
6165
6182
|
return false;
|
|
6166
6183
|
}
|
|
6167
6184
|
}
|