Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

serializeValueToAttribute always provokes distribute if necessary #1580

Merged
merged 5 commits into from
May 21, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions src/lib/dom-api.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,10 @@
},

_lazyDistribute: function(host) {
if (host.shadyRoot) {
// 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;
}
// TODO(sorvell): optimize debounce so it does less work by default
// and then remove these checks...
// need to dirty distribution once.
if (!host.isDebouncerActive('_distribute')) {
host.debounce('_distribute', host._distributeContent);
dirtyRoots.push(host);
}
Expand Down Expand Up @@ -200,7 +197,7 @@
},

_parentNeedsDistribution: function(parent) {
return parent.shadyRoot && hasInsertionPoint(parent.shadyRoot);
return parent && parent.shadyRoot && hasInsertionPoint(parent.shadyRoot);
},

// TODO(sorvell): technically we should check non-fragment nodes for
Expand Down Expand Up @@ -379,7 +376,7 @@
},

_distributeParent: function() {
if (this.parentNode && this.parentNode.shadyRoot) {
if (this._parentNeedsDistribution(this.parentNode)) {
this._lazyDistribute(this.parentNode);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/mini/ready.html
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@
_ready: function() {
// extension point
this._beforeClientsReady();
// prepare root
this._setupRoot();
this._readyClients();
// extension point
this._afterClientsReady();
this._readySelf();
},

_readyClients: function() {
// prepare root
this._setupRoot();
// logically distribute self
this._beginDistribute();
// now fully prepare localChildren
Expand Down
3 changes: 3 additions & 0 deletions src/standard/x-styling.html
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@
value = host._scopeElementClass(node, value);
}
}
// note: using Polymer.dom here ensures that any attribute sets
// will provoke distribution if necessary
node = Polymer.dom(node || this);
serializeValueToAttribute.call(this, value, attribute, node);
},

Expand Down
47 changes: 46 additions & 1 deletion test/unit/polymer-dom-elements.html
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,49 @@
<x-echo id="echo2"><content select=".b"></content></x-echo>
</template>
<script>Polymer({is: 'x-redistribute-a-b'});</script>
</dom-module>
</dom-module>

<dom-module id="x-attr">
<template>Attr1</template>
<script>Polymer({
is: 'x-attr',
hostAttributes: {
bar: 'bar'
},
properties: {
foo: {type: Boolean, reflectToAttribute: true, value: false}
}

});</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>]
Bar: [<content select="[bar]"></content>]
</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>


6 changes: 6 additions & 0 deletions test/unit/polymer-dom-shadow.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@
<div></div>
</x-select-class1>

<x-select-attr>
<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>
Expand Down
6 changes: 6 additions & 0 deletions test/unit/polymer-dom.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@
<div></div>
</x-select-class1>

<x-select-attr>
<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>
Expand Down
30 changes: 30 additions & 0 deletions test/unit/polymer-dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,36 @@ suite('Polymer.dom', function() {
assert.deepEqual(Polymer.dom(ec2).getDistributedNodes(), []);
});

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;
assert.equal(Polymer.dom(c).getDestinationInsertionPoints()[0], ip$[1], 'child not distributed based on host attribute');
c.foo = true;
Polymer.dom.flush();
assert.equal(Polymer.dom(c).getDestinationInsertionPoints()[0], ip$[0], 'child not distributed based on reflecting attribute')
c.foo = false;
Polymer.dom.flush();
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');
Expand Down