Skip to content

Commit

Permalink
Remove support for lazy-upgrade inside dom-if and dom-repeat
Browse files Browse the repository at this point in the history
This is very complicated to set up, and I'm not sure there are actually
any good use cases. If you can control when an element is stamped, you
really don't need to use disable-upgrade on it.
  • Loading branch information
dfreedm committed Mar 21, 2017
1 parent ba60b82 commit 1b4a978
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 46 deletions.
27 changes: 0 additions & 27 deletions lib/mixins/lazy-upgrade-mixin.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@
node.removeAttribute(LAZY_UPGRADE);
}

function eventInCurrentScope(scope, event) {
return event.target === event.composedPath()[0];
}

/** @polymerMixinClass */
return class LazyUpgrade extends base {
static get properties() {
Expand All @@ -84,8 +80,6 @@
}

ready() {
// check for dom-repeat and dom-if elements stamping lazy-upgrade nodes
this.addEventListener('dom-change', (ev) => { this.__lazyUpgradeFromDomChange(ev) });
super.ready();
this.__lazyUpgradeQueue = findCandidates(this.shadowRoot || this);
this._lazyUpgrading = true;
Expand All @@ -108,27 +102,6 @@
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
30 changes: 11 additions & 19 deletions test/unit/lazy-upgrade.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,15 @@
<lazy-child id="two" disable-upgrade lazy-upgrade="1"></lazy-child>
<lazy-child id="three"></lazy-child>
<dom-if lazy-upgrade="1">
<lazy-child id="four" disable-upgrade lazy-upgrade></lazy-child>
<template>
<lazy-child id="four"></lazy-child>
</template>
</dom-if>
<lazy-child id="five" disable-upgrade></lazy-child>
<dom-if lazy-upgrade>
<lazy-child id="six"></lazy-child>
<template>
<lazy-child id="six"></lazy-child>
</template>
</dom-if>
</template>
<script>
Expand Down Expand Up @@ -107,12 +111,6 @@
</dom-if>
<lazy-child id="three" disable-upgrade></lazy-child>
<lazy-child id="four" disable-upgrade lazy-upgrade></lazy-child>
<dom-if lazy-upgrade>
<template>
<lazy-child id="five" disable-upgrade></lazy-child>
<lazy-child id="six" disable-upgrade lazy-upgrade></lazy-child>
</template>
</dom-if>
</template>

<template id="critical">
Expand All @@ -132,13 +130,9 @@
<dom-module id="no-upgrade-shadow">
<template>
<lazy-child id="one" disable-upgrade lazy-upgrade></lazy-child>
<dom-if if>
<template>
<lazy-child id="two" disable-upgrade lazy-upgrade></lazy-child>
</template>
</dom-if>
</template>
</dom-module>

<script>
addEventListener('WebComponentsReady', () => {
customElements.define('no-upgrade-shadow', class extends Polymer.Element {
Expand Down Expand Up @@ -197,12 +191,10 @@
el.appendChild(document.importNode(template.content, true));
el.addEventListener('lazy-upgrade-finished', () => {
let children = el.querySelectorAll('lazy-child');
assert.equal(children.length, 5);
assert.equal(children.length, 3);
assertRendered(children[0], true);
assertRendered(children[1], false);
assertRendered(children[2], true);
assertRendered(children[3], false);
assertRendered(children[4], true);
document.body.removeChild(el);
done();
});
Expand Down Expand Up @@ -235,10 +227,10 @@
assert.equal(children.length, 6);
let expected = [
"three",
"six",
"one",
"four",
"two"
"two",
"six",
"four"
];
assert.deepEqual(el.upgradedChildren.map(n => n.id), expected);
document.body.removeChild(el);
Expand Down

0 comments on commit 1b4a978

Please sign in to comment.