From 9c6f26611e91707727cb3577cc39b90e7104c7a5 Mon Sep 17 00:00:00 2001 From: Steven Orvell Date: Thu, 11 Jul 2019 18:01:32 -0700 Subject: [PATCH] Simplify logic for disable-upgrade --- lib/legacy/class.js | 57 ++++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/lib/legacy/class.js b/lib/legacy/class.js index 5e7062c764..9bfd066bf1 100644 --- a/lib/legacy/class.js +++ b/lib/legacy/class.js @@ -238,6 +238,24 @@ function GenerateClassFromInfo(info, Base, behaviors) { return observedAttributesGetter.call(this).concat(DISABLED_ATTR); } + // Prevent element from initializing properties when it's upgrade disabled. + /** @override */ + _initializeProperties() { + if (!this.hasAttribute(DISABLED_ATTR)) { + super._initializeProperties(); + } else { + this.__isUpgradeDisabled = true; + } + } + + // Prevent element from enabling properties when it's upgrade disabled. + /** @override */ + _enableProperties() { + if (!this.__isUpgradeDisabled) { + super._enableProperties(); + } + } + /** * @override * @param {string} name Attribute name. @@ -248,8 +266,14 @@ function GenerateClassFromInfo(info, Base, behaviors) { */ attributeChangedCallback(name, old, value, namespace) { if (name == DISABLED_ATTR) { - if (!this.__dataEnabled && value == null && this.isConnected) { - super.connectedCallback(); + // When disable-upgrade is removed, intialize properties and + // provoke connectedCallback if the element is already connected. + if (!this.__dataEnabled && value == null) { + super._initializeProperties(); + this.__isUpgradeDisabled = false; + if (this.isConnected) { + super.connectedCallback(); + } } } else { super.attributeChangedCallback( @@ -257,39 +281,18 @@ function GenerateClassFromInfo(info, Base, behaviors) { } } - - // prevent user code in connected from running + // Prevent element from connecting when it's upgrade disabled. /** @override */ connectedCallback() { - if (this.__dataEnabled || !this.hasAttribute(DISABLED_ATTR)) { + if (!this.__isUpgradeDisabled) { super.connectedCallback(); } } - _initializeProperties() { - if (!this.hasAttribute(DISABLED_ATTR)) { - super._initializeProperties(); - } else { - this.__wasDisabled = true; - } - } - - // prevent element from turning on properties - /** @override */ - _enableProperties() { - if (this.__wasDisabled) { - this.__wasDisabled = false; - super._initializeProperties(); - } - if (!this.hasAttribute(DISABLED_ATTR)) { - super._enableProperties(); - } - } - - // only go if "enabled" + // Prevent element from disconnecting when it's upgrade disabled. /** @override */ disconnectedCallback() { - if (this.__dataEnabled) { + if (!this.__isUpgradeDisabled) { super.disconnectedCallback(); } }