Skip to content

Commit 9c6f266

Browse files
author
Steven Orvell
committed
Simplify logic for disable-upgrade
1 parent 9756d86 commit 9c6f266

File tree

1 file changed

+30
-27
lines changed

1 file changed

+30
-27
lines changed

lib/legacy/class.js

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,24 @@ function GenerateClassFromInfo(info, Base, behaviors) {
238238
return observedAttributesGetter.call(this).concat(DISABLED_ATTR);
239239
}
240240

241+
// Prevent element from initializing properties when it's upgrade disabled.
242+
/** @override */
243+
_initializeProperties() {
244+
if (!this.hasAttribute(DISABLED_ATTR)) {
245+
super._initializeProperties();
246+
} else {
247+
this.__isUpgradeDisabled = true;
248+
}
249+
}
250+
251+
// Prevent element from enabling properties when it's upgrade disabled.
252+
/** @override */
253+
_enableProperties() {
254+
if (!this.__isUpgradeDisabled) {
255+
super._enableProperties();
256+
}
257+
}
258+
241259
/**
242260
* @override
243261
* @param {string} name Attribute name.
@@ -248,48 +266,33 @@ function GenerateClassFromInfo(info, Base, behaviors) {
248266
*/
249267
attributeChangedCallback(name, old, value, namespace) {
250268
if (name == DISABLED_ATTR) {
251-
if (!this.__dataEnabled && value == null && this.isConnected) {
252-
super.connectedCallback();
269+
// When disable-upgrade is removed, intialize properties and
270+
// provoke connectedCallback if the element is already connected.
271+
if (!this.__dataEnabled && value == null) {
272+
super._initializeProperties();
273+
this.__isUpgradeDisabled = false;
274+
if (this.isConnected) {
275+
super.connectedCallback();
276+
}
253277
}
254278
} else {
255279
super.attributeChangedCallback(
256280
name, old, value, /** @type {null|string} */ (namespace));
257281
}
258282
}
259283

260-
261-
// prevent user code in connected from running
284+
// Prevent element from connecting when it's upgrade disabled.
262285
/** @override */
263286
connectedCallback() {
264-
if (this.__dataEnabled || !this.hasAttribute(DISABLED_ATTR)) {
287+
if (!this.__isUpgradeDisabled) {
265288
super.connectedCallback();
266289
}
267290
}
268291

269-
_initializeProperties() {
270-
if (!this.hasAttribute(DISABLED_ATTR)) {
271-
super._initializeProperties();
272-
} else {
273-
this.__wasDisabled = true;
274-
}
275-
}
276-
277-
// prevent element from turning on properties
278-
/** @override */
279-
_enableProperties() {
280-
if (this.__wasDisabled) {
281-
this.__wasDisabled = false;
282-
super._initializeProperties();
283-
}
284-
if (!this.hasAttribute(DISABLED_ATTR)) {
285-
super._enableProperties();
286-
}
287-
}
288-
289-
// only go if "enabled"
292+
// Prevent element from disconnecting when it's upgrade disabled.
290293
/** @override */
291294
disconnectedCallback() {
292-
if (this.__dataEnabled) {
295+
if (!this.__isUpgradeDisabled) {
293296
super.disconnectedCallback();
294297
}
295298
}

0 commit comments

Comments
 (0)