Skip to content

Commit 64c1ae5

Browse files
committed
Merge pull request #1580 from Polymer/serialize-distribute
serializeValueToAttribute always provokes distribute if necessary
2 parents 269ef2f + 6ac439b commit 64c1ae5

File tree

7 files changed

+98
-11
lines changed

7 files changed

+98
-11
lines changed

src/lib/dom-api.html

+5-8
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,10 @@
4242
},
4343

4444
_lazyDistribute: function(host) {
45-
if (host.shadyRoot) {
45+
// note: only try to distribute if the root is not clean; this ensures
46+
// we don't distribute before initial distribution
47+
if (host.shadyRoot && host.shadyRoot._distributionClean) {
4648
host.shadyRoot._distributionClean = false;
47-
}
48-
// TODO(sorvell): optimize debounce so it does less work by default
49-
// and then remove these checks...
50-
// need to dirty distribution once.
51-
if (!host.isDebouncerActive('_distribute')) {
5249
host.debounce('_distribute', host._distributeContent);
5350
dirtyRoots.push(host);
5451
}
@@ -200,7 +197,7 @@
200197
},
201198

202199
_parentNeedsDistribution: function(parent) {
203-
return parent.shadyRoot && hasInsertionPoint(parent.shadyRoot);
200+
return parent && parent.shadyRoot && hasInsertionPoint(parent.shadyRoot);
204201
},
205202

206203
// TODO(sorvell): technically we should check non-fragment nodes for
@@ -379,7 +376,7 @@
379376
},
380377

381378
_distributeParent: function() {
382-
if (this.parentNode && this.parentNode.shadyRoot) {
379+
if (this._parentNeedsDistribution(this.parentNode)) {
383380
this._lazyDistribute(this.parentNode);
384381
}
385382
}

src/mini/ready.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,15 @@
9393
_ready: function() {
9494
// extension point
9595
this._beforeClientsReady();
96+
// prepare root
97+
this._setupRoot();
9698
this._readyClients();
9799
// extension point
98100
this._afterClientsReady();
99101
this._readySelf();
100102
},
101103

102104
_readyClients: function() {
103-
// prepare root
104-
this._setupRoot();
105105
// logically distribute self
106106
this._beginDistribute();
107107
// now fully prepare localChildren

src/standard/x-styling.html

+3
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@
162162
value = host._scopeElementClass(node, value);
163163
}
164164
}
165+
// note: using Polymer.dom here ensures that any attribute sets
166+
// will provoke distribution if necessary
167+
node = Polymer.dom(node || this);
165168
serializeValueToAttribute.call(this, value, attribute, node);
166169
},
167170

test/unit/polymer-dom-elements.html

+46-1
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,49 @@
133133
<x-echo id="echo2"><content select=".b"></content></x-echo>
134134
</template>
135135
<script>Polymer({is: 'x-redistribute-a-b'});</script>
136-
</dom-module>
136+
</dom-module>
137+
138+
<dom-module id="x-attr">
139+
<template>Attr1</template>
140+
<script>Polymer({
141+
is: 'x-attr',
142+
hostAttributes: {
143+
bar: 'bar'
144+
},
145+
properties: {
146+
foo: {type: Boolean, reflectToAttribute: true, value: false}
147+
}
148+
149+
});</script>
150+
</dom-module>
151+
152+
<dom-module id="x-attr2">
153+
<template>Attr2</template>
154+
<script>Polymer({
155+
is: 'x-attr2',
156+
properties: {
157+
foo: {type: Boolean, reflectToAttribute: true, value: true}
158+
}
159+
160+
});</script>
161+
</dom-module>
162+
163+
<dom-module id="x-select-attr">
164+
<template>
165+
Foo: [<content select="[foo]"></content>]
166+
Bar: [<content select="[bar]"></content>]
167+
</template>
168+
<script>Polymer({is: 'x-select-attr'});</script>
169+
</dom-module>
170+
171+
<dom-module id="x-compose-select-attr">
172+
<template>
173+
<x-select-attr id="select">
174+
<x-attr id="attr1"></x-attr>
175+
<x-attr2 id="attr2"></x-attr2>
176+
</x-select-attr>
177+
</template>
178+
<script>Polymer({is: 'x-compose-select-attr'});</script>
179+
</dom-module>
180+
181+

test/unit/polymer-dom-shadow.html

+6
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@
3939
<div></div>
4040
</x-select-class1>
4141

42+
<x-select-attr>
43+
<x-attr></x-attr>
44+
</x-select-attr>
45+
46+
<x-compose-select-attr></x-compose-select-attr>
47+
4248
<x-redistribute-a-b></x-redistribute-a-b>
4349

4450
<script src="polymer-dom.js"></script>

test/unit/polymer-dom.html

+6
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@
3838
<div></div>
3939
</x-select-class1>
4040

41+
<x-select-attr>
42+
<x-attr></x-attr>
43+
</x-select-attr>
44+
45+
<x-compose-select-attr></x-compose-select-attr>
46+
4147
<x-redistribute-a-b></x-redistribute-a-b>
4248

4349
<script src="polymer-dom.js"></script>

test/unit/polymer-dom.js

+30
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,36 @@ suite('Polymer.dom', function() {
264264
assert.deepEqual(Polymer.dom(ec2).getDistributedNodes(), []);
265265
});
266266

267+
test('without a host setting hostAttributes/reflecting properties provokes distribution', function() {
268+
var e = document.querySelector('x-select-attr');
269+
var ip$ = Polymer.dom(e.root).querySelectorAll('content');
270+
var c = Polymer.dom(e).firstElementChild;
271+
assert.equal(Polymer.dom(c).getDestinationInsertionPoints()[0], ip$[1], 'child not distributed based on host attribute');
272+
c.foo = true;
273+
Polymer.dom.flush();
274+
assert.equal(Polymer.dom(c).getDestinationInsertionPoints()[0], ip$[0], 'child not distributed based on reflecting attribute')
275+
c.foo = false;
276+
Polymer.dom.flush();
277+
assert.equal(Polymer.dom(c).getDestinationInsertionPoints()[0], ip$[1], 'child not distributed based on reflecting attribute')
278+
});
279+
280+
test('within a host setting hostAttributes/reflecting properties provokes distribution', function() {
281+
var e = document.querySelector('x-compose-select-attr');
282+
var ip$ = Polymer.dom(e.$.select.root).querySelectorAll('content');
283+
var c1 = e.$.attr1;
284+
Polymer.dom.flush();
285+
assert.equal(Polymer.dom(c1).getDestinationInsertionPoints()[0], ip$[1], 'child not distributed based on host attribute');
286+
c1.foo = true;
287+
Polymer.dom.flush();
288+
assert.equal(Polymer.dom(c1).getDestinationInsertionPoints()[0], ip$[0], 'child not distributed based on reflecting attribute')
289+
c1.foo = false;
290+
Polymer.dom.flush();
291+
assert.equal(Polymer.dom(c1).getDestinationInsertionPoints()[0], ip$[1], 'child not distributed based on reflecting attribute')
292+
var c2 = e.$.attr2;
293+
Polymer.dom.flush();
294+
assert.equal(Polymer.dom(c2).getDestinationInsertionPoints()[0], ip$[0], 'child not distributed based on default value');
295+
});
296+
267297
test('appendChild (light)', function() {
268298
var rere = Polymer.dom(testElement.root).querySelector('x-rereproject');
269299
var s = document.createElement('span');

0 commit comments

Comments
 (0)