Skip to content

Commit 1002f4f

Browse files
Revert 824f2ce
Pushing softmatchable nodes to the end broke correctness when `beforeNodeRemoved => false` is in the mix.
1 parent 0d76217 commit 1002f4f

File tree

3 files changed

+10
-37
lines changed

3 files changed

+10
-37
lines changed

PR.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ Speaking of lasagna, here is the tasty meat. By removing the two-pass mode, and
5151
- if match found
5252
- remove any nodes up to the match:
5353
- pantry persistent nodes
54-
- shuffle soft matches to the end for later reuse
5554
- delete the rest
5655
- morph the match
5756
- elsif no match found, and node is persistent

src/idiomorph.js

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,6 @@ var Idiomorph = (function () {
256256
* - if match found
257257
* - remove any nodes up to the match:
258258
* - pantry persistent nodes
259-
* - shuffle soft matches to the end for later reuse
260259
* - delete the rest
261260
* - morph the match
262261
* - elsif no match found, and node is persistent
@@ -304,14 +303,7 @@ var Idiomorph = (function () {
304303
if (bestMatch) {
305304
// if the node to morph is not at the insertion point then remove/move up to it
306305
if (bestMatch !== insertionPoint) {
307-
removeNodesBetween(
308-
ctx,
309-
insertionPoint,
310-
bestMatch,
311-
// additional args so that we can retain future soft matches
312-
newChild.nextSibling,
313-
endPoint,
314-
);
306+
removeNodesBetween(ctx, insertionPoint, bestMatch);
315307
}
316308
morphNode(bestMatch, newChild, ctx);
317309
insertionPoint = bestMatch.nextSibling;
@@ -471,26 +463,16 @@ var Idiomorph = (function () {
471463

472464
/**
473465
* Gets rid of an unwanted DOM node; strategy depends on nature of its reuse:
474-
* - Persistent nodes will be moved to the pantry for later reuse by removeNode
475-
* - Future soft-matchable nodes will be moved to the end of the parent for later reuse
476-
* - Finally, unreusable nodes will have the hooks called, and then are removed
466+
* - Persistent nodes will be moved to the pantry for later reuse
467+
* - Other nodes will have their hooks called, and then are removed
477468
* @param {MorphContext} ctx
478469
* @param {Node} node
479-
* @param {Node|null} nextNewChild
480-
* @param {Node|null} endPoint
481470
*/
482-
function removeNode(ctx, node, nextNewChild = null, endPoint = null) {
471+
function removeNode(ctx, node) {
483472
// are we going to id set match this later?
484473
if (ctx.idMap.has(node) && node instanceof Element) {
485474
// skip callbacks and move to pantry
486475
moveBefore(ctx.pantry, node, null);
487-
488-
// will be soft-matched to an upcoming new sibling?
489-
} else if (findBestMatch(ctx, node, nextNewChild, null)) {
490-
// skip callbacks and move to the end of the parent for later soft matching
491-
moveBefore(/** @type {Element} */ (node.parentNode), node, endPoint);
492-
493-
// unreusable
494476
} else {
495477
// remove for realsies
496478
if (ctx.callbacks.beforeNodeRemoved(node) === false) return;
@@ -504,24 +486,16 @@ var Idiomorph = (function () {
504486
* @param {MorphContext} ctx
505487
* @param {Node} startInclusive
506488
* @param {Node} endExclusive
507-
* @param {Node|null} nextNewChild
508-
* @param {Node|null} endPoint
509489
* @returns {Node|null}
510490
*/
511-
function removeNodesBetween(
512-
ctx,
513-
startInclusive,
514-
endExclusive,
515-
nextNewChild,
516-
endPoint,
517-
) {
491+
function removeNodesBetween(ctx, startInclusive, endExclusive) {
518492
/** @type {Node | null} */
519493
let cursor = startInclusive;
520494
// remove nodes until the endExclusive node
521495
while (cursor && cursor !== endExclusive) {
522496
let tempNode = /** @type {Node} */ (cursor);
523497
cursor = cursor.nextSibling;
524-
removeNode(ctx, tempNode, nextNewChild, endPoint);
498+
removeNode(ctx, tempNode);
525499
}
526500
return cursor;
527501
}

test/ops.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ describe("morphing operations", function () {
6161
);
6262
});
6363

64-
it.skip("prepending a new softmatchable node onto the beginning", function () {
64+
it("prepending a new softmatchable node onto the beginning", function () {
6565
assertOps(
6666
"<section><a>A</a><a>B</a></section>",
6767
"<section><a>New</a><a>A</a><a>B</a></section>",
@@ -78,7 +78,7 @@ describe("morphing operations", function () {
7878
);
7979
});
8080

81-
it.skip("inserting a new softmatchable node into the middle", function () {
81+
it("inserting a new softmatchable node into the middle", function () {
8282
assertOps(
8383
"<section><a>A</a><a>B</a><a>C</a><a>D</a></section>",
8484
"<section><a>A</a><a>B</a><a>New</a><a>C</a><a>D</a></section>",
@@ -114,7 +114,7 @@ describe("morphing operations", function () {
114114
);
115115
});
116116

117-
it.skip("removing a softmatchable node from the front", function () {
117+
it("removing a softmatchable node from the front", function () {
118118
assertOps(
119119
"<section><a>A</a><a>B</a><a>C</a></section>",
120120
"<section><a>B</a><a>C</a></section>",
@@ -131,7 +131,7 @@ describe("morphing operations", function () {
131131
);
132132
});
133133

134-
it.skip("removing a softmatchable node from the middle", function () {
134+
it("removing a softmatchable node from the middle", function () {
135135
assertOps(
136136
"<section><a>A</a><a>B</a><a>C</a></section>",
137137
"<section><a>A</a><a>C</a></section>",

0 commit comments

Comments
 (0)