Skip to content

Commit ea977a0

Browse files
committed
better subset mapping, fixes #69
1 parent 9e6c5fb commit ea977a0

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

diffDOM.js

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,9 +1191,6 @@
11911191
map.oldValue = diff[t._const.to];
11921192
}
11931193
});
1194-
if (node.subsets && newSubsets.length) {
1195-
node.subsets = node.subsets.concat(newSubsets);
1196-
}
11971194
}
11981195

11991196
break;
@@ -1218,13 +1215,8 @@
12181215
}
12191216
}
12201217
});
1221-
parentNode.subsets = parentNode.subsets.filter(function(map) {
1222-
return !map.delete;
1223-
});
1224-
if (newSubsets.length) {
1225-
parentNode.subsets = parentNode.subsets.concat(newSubsets);
1226-
}
12271218
}
1219+
node = parentNode;
12281220
break;
12291221
case this._const.addElement:
12301222
route = diff[this._const.route].slice();
@@ -1248,7 +1240,7 @@
12481240
node.subsets.forEach(function(map) {
12491241
if (map.oldValue >= c) {
12501242
map.oldValue += 1;
1251-
} if (map.oldValue < c && (map.oldValue + map.length) > c) {
1243+
} else if (map.oldValue < c && (map.oldValue + map.length) > c) {
12521244
splitLength = map.oldValue + map.length - c
12531245
newSubsets.push({
12541246
newValue: map.newValue + map.length - splitLength,
@@ -1284,13 +1276,8 @@
12841276
}
12851277
}
12861278
});
1287-
parentNode.subsets = parentNode.subsets.filter(function(map) {
1288-
return !map.delete;
1289-
});
1290-
if (newSubsets.length) {
1291-
parentNode.subsets = parentNode.subsets.concat(newSubsets);
1292-
}
12931279
}
1280+
node = parentNode;
12941281
break;
12951282
case this._const.addTextElement:
12961283
route = diff[this._const.route].slice();
@@ -1331,6 +1318,15 @@
13311318
console.log('unknown action');
13321319
}
13331320

1321+
if (node.subsets) {
1322+
node.subsets = node.subsets.filter(function(map) {
1323+
return !map.delete && map.oldValue !== map.newValue;
1324+
});
1325+
if (newSubsets.length) {
1326+
node.subsets = node.subsets.concat(newSubsets);
1327+
}
1328+
}
1329+
13341330
// capture newNode for the callback
13351331
info.newNode = newNode;
13361332
this.postVirtualDiffApply(info);

0 commit comments

Comments
 (0)