Skip to content

Commit

Permalink
Merge pull request #39 from webcomponents/38-kschaaf-append-during-co…
Browse files Browse the repository at this point in the history
…mposition

Set the root to "clean" before composition. Fixes #38
  • Loading branch information
Steve Orvell authored Oct 12, 2016
2 parents 15e5b14 + b8259a8 commit bf81867
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 10 deletions.
4 changes: 2 additions & 2 deletions shadydom.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion shadydom.min.js.map

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions src/shady.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ let ShadyMixin = {
tree.Logical.saveChildNodes(host);
tree.Logical.saveChildNodes(this);
// state flags
this._clean = true;
this._renderPending = false;
this._hasRendered = false;
this._distributor = new Distributor(this);
this.update();
Expand All @@ -59,9 +59,9 @@ let ShadyMixin = {
// distribute this host).
update() {
let distributionRoot = this._findDistributionRoot(this.host);
//console.log('update from', this.host, 'root', distributionRoot.host, distributionRoot._clean);
if (distributionRoot._clean) {
distributionRoot._clean = false;
//console.log('update from', this.host, 'root', distributionRoot.host, distributionRoot._renderPending);
if (!distributionRoot._renderPending) {
distributionRoot._renderPending = true;
enqueue(function() {
distributionRoot.render();
});
Expand Down Expand Up @@ -91,7 +91,8 @@ let ShadyMixin = {
},

render() {
if (!this._clean) {
if (this._renderPending) {
this._renderPending = false;
if (!this._skipUpdateInsertionPoints) {
this.updateInsertionPoints();
} else if (!this._hasRendered) {
Expand All @@ -114,13 +115,12 @@ let ShadyMixin = {
this.distribute();
// physical
this.compose();
this._clean = true;
this._hasRendered = true;
}
},

forceRender() {
this._clean = false;
this._renderPending = true;
this.render();
},

Expand Down
21 changes: 21 additions & 0 deletions tests/shady-dynamic.html
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,14 @@
<button>click me</button>
</x-outer>

<script>
defineTestElement('x-stamps-peer', function() {
var span = document.createElement('span');
span.setAttribute('id', 'peer');
this.parentNode.appendChild(span);
});
</script>

<script>

'use strict';
Expand Down Expand Up @@ -860,6 +868,19 @@
document.body.removeChild(re);
});

test('synchronous append during distribution', function() {
var echo = document.createElement('x-echo');
document.body.appendChild(echo);
customElements.flush();
// When connected will cause span#peer to be added after it,
// which should also be distributed
echo.appendChild(document.createElement('x-stamps-peer'));
ShadyDOM.flush();
var assignedNodes = echo.shadowRoot.firstElementChild.assignedNodes();
assert.equal(assignedNodes[0].localName, 'x-stamps-peer');
assert.equal(assignedNodes[1].id, 'peer');
});

});

suite('Accessors', function() {
Expand Down

0 comments on commit bf81867

Please sign in to comment.