slight simplification and add tests for changes within a host.

This commit is contained in:
Steven Orvell
2015-05-20 18:14:43 -07:00
parent 09b0081cf1
commit 8cdac2661c
6 changed files with 52 additions and 8 deletions

View File

@@ -42,12 +42,12 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
},
_lazyDistribute: function(host) {
// note: only try to distribute if the root is not clean; this ensures
// we don't distribute before initial distribution
if (host.shadyRoot && host.shadyRoot._distributionClean) {
host.shadyRoot._distributionClean = false;
if (!host.isDebouncerActive('_distribute')) {
host.debounce('_distribute', host._distributeContent);
dirtyRoots.push(host);
}
host.debounce('_distribute', host._distributeContent);
dirtyRoots.push(host);
}
},

View File

@@ -93,6 +93,8 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
_ready: function() {
// extension point
this._beforeClientsReady();
// prepare root
this._setupRoot();
this._readyClients();
// extension point
this._afterClientsReady();
@@ -100,8 +102,6 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
},
_readyClients: function() {
// prepare root
this._setupRoot();
// logically distribute self
this._beginDistribute();
// now fully prepare localChildren

View File

@@ -136,7 +136,7 @@
</dom-module>
<dom-module id="x-attr">
<template>Host attr</template>
<template>Attr1</template>
<script>Polymer({
is: 'x-attr',
hostAttributes: {
@@ -149,6 +149,17 @@
});</script>
</dom-module>
<dom-module id="x-attr2">
<template>Attr2</template>
<script>Polymer({
is: 'x-attr2',
properties: {
foo: {type: Boolean, reflectToAttribute: true, value: true}
}
});</script>
</dom-module>
<dom-module id="x-select-attr">
<template>
Foo: [<content select="[foo]"></content>]
@@ -156,3 +167,15 @@
</template>
<script>Polymer({is: 'x-select-attr'});</script>
</dom-module>
<dom-module id="x-compose-select-attr">
<template>
<x-select-attr id="select">
<x-attr id="attr1"></x-attr>
<x-attr2 id="attr2"></x-attr2>
</x-select-attr>
</template>
<script>Polymer({is: 'x-compose-select-attr'});</script>
</dom-module>

View File

@@ -43,6 +43,8 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
<x-attr></x-attr>
</x-select-attr>
<x-compose-select-attr></x-compose-select-attr>
<x-redistribute-a-b></x-redistribute-a-b>
<script src="polymer-dom.js"></script>

View File

@@ -42,6 +42,8 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
<x-attr></x-attr>
</x-select-attr>
<x-compose-select-attr></x-compose-select-attr>
<x-redistribute-a-b></x-redistribute-a-b>
<script src="polymer-dom.js"></script>

View File

@@ -264,7 +264,7 @@ suite('Polymer.dom', function() {
assert.deepEqual(Polymer.dom(ec2).getDistributedNodes(), []);
});
test('setting hostAttributes/reflecting properties provokes distribution', function() {
test('without a host setting hostAttributes/reflecting properties provokes distribution', function() {
var e = document.querySelector('x-select-attr');
var ip$ = Polymer.dom(e.root).querySelectorAll('content');
var c = Polymer.dom(e).firstElementChild;
@@ -277,6 +277,23 @@ suite('Polymer.dom', function() {
assert.equal(Polymer.dom(c).getDestinationInsertionPoints()[0], ip$[1], 'child not distributed based on reflecting attribute')
});
test('within a host setting hostAttributes/reflecting properties provokes distribution', function() {
var e = document.querySelector('x-compose-select-attr');
var ip$ = Polymer.dom(e.$.select.root).querySelectorAll('content');
var c1 = e.$.attr1;
Polymer.dom.flush();
assert.equal(Polymer.dom(c1).getDestinationInsertionPoints()[0], ip$[1], 'child not distributed based on host attribute');
c1.foo = true;
Polymer.dom.flush();
assert.equal(Polymer.dom(c1).getDestinationInsertionPoints()[0], ip$[0], 'child not distributed based on reflecting attribute')
c1.foo = false;
Polymer.dom.flush();
assert.equal(Polymer.dom(c1).getDestinationInsertionPoints()[0], ip$[1], 'child not distributed based on reflecting attribute')
var c2 = e.$.attr2;
Polymer.dom.flush();
assert.equal(Polymer.dom(c2).getDestinationInsertionPoints()[0], ip$[0], 'child not distributed based on default value');
});
test('appendChild (light)', function() {
var rere = Polymer.dom(testElement.root).querySelector('x-rereproject');
var s = document.createElement('span');