mirror of
https://github.com/Polymer/polymer.git
synced 2026-08-19 01:14:44 -05:00
Fixes #2235. Manages logical information in shady distribution more directly by capturing it explicitly when needed and not whenever distribution is run.
This commit is contained in:
@@ -223,8 +223,14 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
||||
},
|
||||
|
||||
_updateInsertionPoints: function(host) {
|
||||
host.shadyRoot._insertionPoints =
|
||||
var i$ = host.shadyRoot._insertionPoints =
|
||||
factory(host.shadyRoot).querySelectorAll(CONTENT);
|
||||
// ensure <content>'s and their parents have logical dom info.
|
||||
for (var i=0, c; i < i$.length; i++) {
|
||||
c = i$[i];
|
||||
saveLightChildrenIfNeeded(c);
|
||||
saveLightChildrenIfNeeded(factory(c).parentNode);
|
||||
}
|
||||
},
|
||||
|
||||
// a node is in a shadyRoot, is a shadyRoot,
|
||||
|
||||
+10
-8
@@ -53,11 +53,19 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
||||
this.shadyRoot._isShadyRoot = true;
|
||||
this.shadyRoot._dirtyRoots = [];
|
||||
// capture insertion point list
|
||||
this.shadyRoot._insertionPoints = !this._notes ||
|
||||
var i$ = this.shadyRoot._insertionPoints = !this._notes ||
|
||||
this._notes._hasContent ?
|
||||
this.shadyRoot.querySelectorAll('content') : [];
|
||||
// save logical tree info for shadyRoot.
|
||||
// save logical tree info
|
||||
// a. for shadyRoot
|
||||
// b. for insertion points (fallback)
|
||||
// c. for parents of insertion points
|
||||
saveLightChildrenIfNeeded(this.shadyRoot);
|
||||
for (var i=0, c; i < i$.length; i++) {
|
||||
c = i$[i];
|
||||
saveLightChildrenIfNeeded(c);
|
||||
saveLightChildrenIfNeeded(c.parentNode);
|
||||
}
|
||||
this.shadyRoot.host = this;
|
||||
},
|
||||
|
||||
@@ -406,9 +414,6 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
||||
}
|
||||
// remove child from its old parent first
|
||||
remove(newChild);
|
||||
// make sure we never lose logical DOM information:
|
||||
// if the parentNode doesn't have lightChildren, save that information now.
|
||||
saveLightChildrenIfNeeded(parentNode);
|
||||
// insert it into the real DOM
|
||||
nativeInsertBefore.call(parentNode, newChild, refChild || null);
|
||||
newChild._composedParent = parentNode;
|
||||
@@ -417,9 +422,6 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
||||
function remove(node) {
|
||||
var parentNode = getComposedParent(node);
|
||||
if (parentNode) {
|
||||
// make sure we never lose logical DOM information:
|
||||
// if the parentNode doesn't have lightChildren, save that information now.
|
||||
saveLightChildrenIfNeeded(parentNode);
|
||||
node._composedParent = null;
|
||||
// remove it from the real DOM
|
||||
nativeRemoveChild.call(parentNode, node);
|
||||
|
||||
@@ -47,6 +47,12 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
||||
|
||||
<x-redistribute-a-b></x-redistribute-a-b>
|
||||
|
||||
<div id="container">
|
||||
<x-echo></x-echo>
|
||||
<span>1</span>
|
||||
<span>2</span>
|
||||
</div>
|
||||
|
||||
<script src="polymer-dom.js"></script>
|
||||
|
||||
</body>
|
||||
|
||||
@@ -47,6 +47,12 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
||||
|
||||
<x-redistribute-a-b></x-redistribute-a-b>
|
||||
|
||||
<div id="container">
|
||||
<x-echo></x-echo>
|
||||
<span>1</span>
|
||||
<span>2</span>
|
||||
</div>
|
||||
|
||||
<script src="polymer-dom.js"></script>
|
||||
|
||||
</body>
|
||||
|
||||
@@ -424,6 +424,34 @@ suite('Polymer.dom', function() {
|
||||
assert.equal(Polymer.dom(rere.root).querySelectorAll('span').length, 0);
|
||||
});
|
||||
|
||||
test('appendChild interacts with unmanaged parent tree', function() {
|
||||
var container = document.querySelector('#container');
|
||||
var echo = Polymer.dom(container).firstElementChild;
|
||||
assert.equal(echo.localName, 'x-echo');
|
||||
var s1 = Polymer.dom(echo).nextElementSibling;
|
||||
assert.equal(s1.textContent, '1');
|
||||
var s2 = Polymer.dom(s1).nextElementSibling;
|
||||
assert.equal(s2.textContent, '2');
|
||||
assert.equal(Polymer.dom(container).children.length, 3);
|
||||
Polymer.dom(echo).appendChild(s1);
|
||||
Polymer.dom.flush();
|
||||
assert.equal(Polymer.dom(container).children.length, 2);
|
||||
assert.equal(Polymer.dom(echo).nextElementSibling, s2);
|
||||
Polymer.dom(echo).appendChild(s2);
|
||||
Polymer.dom.flush();
|
||||
assert.equal(Polymer.dom(container).children.length, 1);
|
||||
assert.equal(Polymer.dom(echo).nextElementSibling, null);
|
||||
Polymer.dom(container).appendChild(s1);
|
||||
Polymer.dom.flush();
|
||||
assert.equal(Polymer.dom(container).children.length, 2);
|
||||
assert.equal(Polymer.dom(echo).nextElementSibling, s1);
|
||||
Polymer.dom(container).appendChild(s2);
|
||||
Polymer.dom.flush();
|
||||
assert.equal(Polymer.dom(container).children.length, 3);
|
||||
assert.equal(Polymer.dom(echo).nextElementSibling, s1);
|
||||
assert.equal(Polymer.dom(s1).nextElementSibling, s2);
|
||||
});
|
||||
|
||||
test('distribute (forced)', function() {
|
||||
var rere = Polymer.dom(testElement.root).querySelector('x-rereproject');
|
||||
var re = Polymer.dom(rere.root).querySelector('x-reproject');
|
||||
|
||||
@@ -473,7 +473,7 @@ function setRootInnerHTML(root, value) {
|
||||
}
|
||||
|
||||
function updateRootInsertionPoints(root) {
|
||||
root._insertionPoints = root.querySelectorAll('content');
|
||||
Polymer.dom(root.host)._updateInsertionPoints(root.host);
|
||||
}
|
||||
|
||||
function getComposedHTML(node) {
|
||||
|
||||
Reference in New Issue
Block a user