Skip to content

Commit

Permalink
move dom-change listener for lazy-upgrade before super.ready()
Browse files Browse the repository at this point in the history
  • Loading branch information
dfreedm committed Mar 20, 2017
1 parent 38e8b8e commit ba60b82
Showing 1 changed file with 24 additions and 19 deletions.
43 changes: 24 additions & 19 deletions lib/mixins/lazy-upgrade-mixin.html
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -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();
}
}
}
});
})();
Expand Down

0 comments on commit ba60b82

Please sign in to comment.