Skip to content

Commit

Permalink
Simplify fix for fragment children management.
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Orvell committed Jan 23, 2016
1 parent 25da63d commit 713377e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
19 changes: 11 additions & 8 deletions src/lib/dom-api-shady.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@
'of this node');
}
// remove node from its current position iff it's in a tree.
var isFragment = node.nodeType === Node.DOCUMENT_FRAGMENT_NODE;
if (!isFragment) {
if (node.nodeType !== Node.DOCUMENT_FRAGMENT_NODE) {
var parent = TreeApi.Logical.getParentNode(node);
// notify existing parent that this node is being removed.
if (parent) {
Expand All @@ -82,11 +81,6 @@
} else {
TreeApi.Composed.appendChild(container, node);
}
// if a fragment provoked distribution, clean up it's actual dom.
} else if (isFragment) {
while (node.firstChild) {
node.removeChild(node.firstChild);
}
}
this.notifyObserver();
return node;
Expand All @@ -105,8 +99,17 @@
TreeApi.Logical.recordInsertBefore(node, this.node, ref_node);
}
// if not distributing and not adding to host, do a fast path addition
return (this._maybeDistribute(node) ||
var handled = (this._maybeDistribute(node) ||
this._tryRemoveUndistributedNode(node));
// if distribution is handling this node and it's a fragment,
// the actual dom may not be removed from the fragment if some nodes
// remain undistributed so we ensure removal here.
if (handled && (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE)) {
while (node.firstChild) {
node.removeChild(node.firstChild);
}
}
return handled;
},

/**
Expand Down
6 changes: 1 addition & 5 deletions src/lib/dom-tree-api.html
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,7 @@
// the act of setting this info can affect patched nodes
// getters; therefore capture childNodes before patching.
for (var n=node.firstChild; n; n=n.nextSibling) {
// only link in the child iff it's not already in the container's
// logical tree.
if (this.getParentNode(n) !== container) {
this._linkNode(n, container, ref_node);
}
this._linkNode(n, container, ref_node);
}
} else {
this._linkNode(node, container, ref_node);
Expand Down

0 comments on commit 713377e

Please sign in to comment.