From ba60b820a96f31da8a2d7f5d46479d55a22c278f Mon Sep 17 00:00:00 2001 From: Daniel Freedman Date: Mon, 20 Mar 2017 13:57:51 -0700 Subject: [PATCH] move dom-change listener for lazy-upgrade before `super.ready()` --- lib/mixins/lazy-upgrade-mixin.html | 43 +++++++++++++++++------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/lib/mixins/lazy-upgrade-mixin.html b/lib/mixins/lazy-upgrade-mixin.html index 174cedc0f6..c70a325b36 100644 --- a/lib/mixins/lazy-upgrade-mixin.html +++ b/lib/mixins/lazy-upgrade-mixin.html @@ -84,27 +84,11 @@ } ready() { - super.ready(); // check for dom-repeat and dom-if elements stamping lazy-upgrade nodes - this.addEventListener('dom-change', (ev) => { - if (!eventInCurrentScope(this, ev)) { - return; - } - let root = ev.composedPath()[0].parentNode; - let candidates = findCandidates(root); - for (let i = 0; i < candidates.length; i++) { - let c = candidates[i]; - if (this.__lazyUpgradeQueue.indexOf(c) === -1) { - this.__lazyUpgradeQueue.push(c); - } - } - if (candidates.length && !this._lazyUpgrading) { - this._lazyUpgrading = true; - this.__lazyUpgrade(); - } - }); - this._lazyUpgrading = true; + this.addEventListener('dom-change', (ev) => { this.__lazyUpgradeFromDomChange(ev) }); + super.ready(); this.__lazyUpgradeQueue = findCandidates(this.shadowRoot || this); + this._lazyUpgrading = true; this.__lazyUpgrade(); } @@ -124,6 +108,27 @@ this._lazyUpgrading = false; } } + + /** + * @private + */ + __lazyUpgradeFromDomChange(ev) { + if (!eventInCurrentScope(this, ev)) { + return; + } + let root = ev.composedPath()[0].parentNode; + let candidates = findCandidates(root); + for (let i = 0; i < candidates.length; i++) { + let c = candidates[i]; + if (this.__lazyUpgradeQueue.indexOf(c) === -1) { + this.__lazyUpgradeQueue.push(c); + } + } + if (candidates.length && !this._lazyUpgrading) { + this._lazyUpgrading = true; + this.__lazyUpgrade(); + } + } } }); })();