From c2f31edaa5596f9ab6c7770aba9578170cb7b1c7 Mon Sep 17 00:00:00 2001 From: Kevin Schaaf Date: Wed, 19 Jun 2019 16:36:47 -0700 Subject: [PATCH] Refactor DomIf into separate subclasses. --- lib/elements/dom-if.js | 324 ++++++++++++++++++++------------- lib/mixins/property-effects.js | 6 +- lib/utils/templatize.js | 1 + 3 files changed, 197 insertions(+), 134 deletions(-) diff --git a/lib/elements/dom-if.js b/lib/elements/dom-if.js index 8c09d91293..5b801856af 100644 --- a/lib/elements/dom-if.js +++ b/lib/elements/dom-if.js @@ -40,7 +40,7 @@ import { showHideChildren } from '../utils/templatize.js'; * @summary Custom element that conditionally stamps and hides or removes * template content based on a boolean flag. */ -export class DomIf extends PolymerElement { +class DomIfBase extends PolymerElement { // Not needed to find template; can be removed once the analyzer // can find the tag name from customElements.define call @@ -87,10 +87,7 @@ export class DomIf extends PolymerElement { constructor() { super(); this.__renderDebouncer = null; - this.__syncProps = null; - this.__instance = null; this._lastIf = false; - this.__ctor = null; this.__hideTemplateChildren__ = false; } @@ -145,6 +142,56 @@ export class DomIf extends PolymerElement { } } + __ensureTemplate() { + // When `removeNestedTemplates` is true, the "template" is the element + // itself, which has been given a `_templateInfo` property + let template = this._templateInfo ? this : + /** @type {HTMLTemplateElement} */(wrap(this).querySelector('template')); + if (!template) { + // Wait until childList changes and template should be there by then + let observer = new MutationObserver(() => { + if (wrap(this).querySelector('template')) { + observer.disconnect(); + this.__render(); + } else { + throw new Error('dom-if requires a