mirror of
https://github.com/Polymer/polymer.git
synced 2025-02-25 18:55:30 -06:00
Ensure fragments added via Polymer.dom always have elements removed, even when distribution does not select those elements.
This commit is contained in:
parent
9f2464df69
commit
101eb3dbd5
@ -56,7 +56,8 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
|||||||
'of this node');
|
'of this node');
|
||||||
}
|
}
|
||||||
// remove node from its current position iff it's in a tree.
|
// remove node from its current position iff it's in a tree.
|
||||||
if (node.nodeType !== Node.DOCUMENT_FRAGMENT_NODE) {
|
var isFragment = node.nodeType === Node.DOCUMENT_FRAGMENT_NODE;
|
||||||
|
if (!isFragment) {
|
||||||
var parent = TreeApi.Logical.getParentNode(node);
|
var parent = TreeApi.Logical.getParentNode(node);
|
||||||
// notify existing parent that this node is being removed.
|
// notify existing parent that this node is being removed.
|
||||||
if (parent) {
|
if (parent) {
|
||||||
@ -81,6 +82,11 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
|||||||
} else {
|
} else {
|
||||||
TreeApi.Composed.appendChild(container, node);
|
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();
|
this.notifyObserver();
|
||||||
return node;
|
return node;
|
||||||
|
@ -1439,6 +1439,16 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('adding a document fragment always clears nodes in the fragment', function() {
|
||||||
|
var x = document.createElement('x-dist-star');
|
||||||
|
var frag = document.createDocumentFragment();
|
||||||
|
frag.appendChild(document.createTextNode('hi'));
|
||||||
|
frag.appendChild(document.createElement('div'));
|
||||||
|
Polymer.dom(x).appendChild(frag);
|
||||||
|
Polymer.dom.flush();
|
||||||
|
assert.equal(frag.childNodes.length, 0);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user