Skip to content

Commit

Permalink
Fixes #1394
Browse files Browse the repository at this point in the history
  • Loading branch information
sorvell committed Apr 10, 2015
1 parent e86bb64 commit ab5d8c9
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 5 deletions.
9 changes: 5 additions & 4 deletions src/mini/shady.html
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
_beginDistribute: function() {
if (this._useContent && hasInsertionPoint(this.shadyRoot)) {
// reset distributions
this._resetDistribution(this.shadyRoot);
this._resetDistribution();
// compute which nodes should be distributed where
// TODO(jmesserly): this is simplified because we assume a single
// ShadowRoot per host and no `<shadow>`.
Expand Down Expand Up @@ -135,17 +135,18 @@
// Many of the following methods are all conceptually static, but they are
// included here as "protected" methods to allow overriding.

_resetDistribution: function(node) {
_resetDistribution: function() {
// light children
var children = getLightChildren(node);
var children = getLightChildren(this);
for (var i = 0; i < children.length; i++) {
var child = children[i];
if (child._destinationInsertionPoints) {
child._destinationInsertionPoints = undefined;
}
}
// insertion points
var p$ = node._insertionPoints;
var root = this.shadyRoot;
var p$ = root._insertionPoints;
for (var j = 0; j < p$.length; j++) {
p$[j]._distributedNodes = [];
}
Expand Down
25 changes: 24 additions & 1 deletion test/unit/polymer-dom-elements.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,27 @@
Polymer({
is: 'x-test-no-distribute'
});
</script>
</script>

<dom-module id="x-distribute">
<template>
<div>
<span>Elements without test attribute</span>
<div id="notTestContainer" style="color: white; background-color: green; min-height: 1em;">
<content id="notTestContent" select=":not([test])"></content>
</div>
<span>Elements with test attribute</span>
<div style="color: white; background-color: red; min-height: 1em;">
<div id="testContainer">
<content id="testContent" select="[test]"></content>
</div>
</div>
</div>
</template>
</dom-element>

<script>
Polymer({
is: "x-distribute"
});
</script>
38 changes: 38 additions & 0 deletions test/unit/polymer-dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,4 +335,42 @@ suite('Polymer.dom non-distributed elements', function() {
assert.equal(Polymer.dom(nd.root).children.length, 1, 'root children length not decremented due to element removal');
});

test('distributeContent correctly distributes changes to light dom', function() {
var shady = !Polymer.Settings.useShadow;
function testNoAttr() {
assert.equal(Polymer.dom(child).getDestinationInsertionPoints()[0], d.$.notTestContent, 'child not distributed logically');
if (shady) {
assert.equal(child.parentNode, d.$.notTestContainer, 'child not rendered in composed dom');
}
}
function testWithAttr() {
assert.equal(Polymer.dom(child).getDestinationInsertionPoints()[0], d.$.testContent, 'child not distributed logically');
if (shady) {
assert.equal(child.parentNode, d.$.testContainer, 'child not rendered in composed dom');
}
}
// test with x-distribute
var d = document.createElement('x-distribute');
document.body.appendChild(d);
var child = document.createElement('div');
child.classList.add('child');
child.textContent = 'Child';
Polymer.dom(d).appendChild(child);
Polymer.dom.flush();
assert.equal(Polymer.dom(d).children[0], child, 'child not added to logical dom');
testNoAttr();
// set / unset `test` attr and see if it distributes properly
child.setAttribute('test', '');
d.distributeContent();
testWithAttr();
//
child.removeAttribute('test');
d.distributeContent();
testNoAttr();
//
child.setAttribute('test', '');
d.distributeContent();
testWithAttr();
});

});

0 comments on commit ab5d8c9

Please sign in to comment.