From 3e6832977b2c60b279fbc7dcf0257dc2b18f65f1 Mon Sep 17 00:00:00 2001 From: Steven Orvell Date: Tue, 7 Mar 2017 12:42:06 -0800 Subject: [PATCH] Fix 4387. Ensure `dom-change` fired with `composed: true`. --- lib/elements/dom-bind.html | 5 ++++- lib/elements/dom-if.html | 5 ++++- lib/elements/dom-repeat.html | 5 ++++- test/unit/dom-if.html | 13 +++++++++++++ test/unit/dom-repeat.html | 16 ++++++++++++++++ 5 files changed, 41 insertions(+), 3 deletions(-) diff --git a/lib/elements/dom-bind.html b/lib/elements/dom-bind.html index 03eda3adaa..d08ca0e37c 100644 --- a/lib/elements/dom-bind.html +++ b/lib/elements/dom-bind.html @@ -94,7 +94,10 @@ this._flushProperties(); } this.__insertChildren(); - this.dispatchEvent(new CustomEvent('dom-change', {bubbles: true})); + this.dispatchEvent(new CustomEvent('dom-change', { + bubbles: true, + composed: true + })); } } diff --git a/lib/elements/dom-if.html b/lib/elements/dom-if.html index 36fc117ce4..842e5a6593 100644 --- a/lib/elements/dom-if.html +++ b/lib/elements/dom-if.html @@ -155,7 +155,10 @@ this._showHideChildren(); } if (this.if != this._lastIf) { - this.dispatchEvent(new CustomEvent('dom-change', {bubbles: true})); + this.dispatchEvent(new CustomEvent('dom-change', { + bubbles: true, + composed: true + })); this._lastIf = this.if; } } diff --git a/lib/elements/dom-repeat.html b/lib/elements/dom-repeat.html index dbd2623052..0b7ee3f5f3 100644 --- a/lib/elements/dom-repeat.html +++ b/lib/elements/dom-repeat.html @@ -488,7 +488,10 @@ // Set rendered item count this._setRenderedItemCount(this.__instances.length); // Notify users - this.dispatchEvent(new CustomEvent('dom-change', {bubbles: true})); + this.dispatchEvent(new CustomEvent('dom-change', { + bubbles: true, + composed: true + })); // Check to see if we need to render more items this.__tryRenderChunk(); } diff --git a/test/unit/dom-if.html b/test/unit/dom-if.html index e3e653c011..d1305b1531 100644 --- a/test/unit/dom-if.html +++ b/test/unit/dom-if.html @@ -126,6 +126,19 @@ assert.equal(stamped[2].prop, 'nice'); }); + test('dom-change event composed, bubbles outside dom-if scope', function() { + var domChangeFired = 0; + var domIf = configured.$['if-1']; + configured.addEventListener('dom-change', function() { + domChangeFired++; + }); + domIf.if = !domIf.if; + domIf.render(); + domIf.if = !domIf.if; + domIf.render(); + assert.equal(domChangeFired, 2); + }); + }); suite('nested individually-controlled dom-if', function() { diff --git a/test/unit/dom-repeat.html b/test/unit/dom-repeat.html index 5ef3b1bd45..79176432f9 100644 --- a/test/unit/dom-repeat.html +++ b/test/unit/dom-repeat.html @@ -4098,6 +4098,22 @@

x-repeat-chunked

}); + suite('dom-change composed', function() { + + test('dom-change event composed, bubbles outside dom-if scope', function() { + var el = fixture('simple'); + var domChangeFired = 0; + el.addEventListener('dom-change', function() { + domChangeFired++; + }); + el.push('items', {prop: 'added1'}); + Polymer.flush(); + el.push('items', {prop: 'added2'}); + Polymer.flush(); + assert.equal(domChangeFired, 2); + }); + }) + })();