From f8f903cf599c2feb02da590dc920891b0e0764ab Mon Sep 17 00:00:00 2001 From: Steven Orvell Date: Mon, 6 Feb 2017 15:27:53 -0800 Subject: [PATCH] Change `isInert` to `disable-upgrade` and feature is now supported only via the `disable-upgrade` attribute. --- src/lib/annotations/annotations.html | 9 ++-- src/lib/base.html | 47 ++++++++-------- test/runner.html | 2 +- ...ness.html => element-disable-upgrade.html} | 54 +++++++++---------- 4 files changed, 53 insertions(+), 59 deletions(-) rename test/unit/{element-inertness.html => element-disable-upgrade.html} (65%) diff --git a/src/lib/annotations/annotations.html b/src/lib/annotations/annotations.html index bcd6879316..acfdcb06bc 100644 --- a/src/lib/annotations/annotations.html +++ b/src/lib/annotations/annotations.html @@ -66,7 +66,7 @@ // null-array (shared empty array to avoid null-checks) Polymer.nar = []; - var inertEnabled = Polymer.Settings.enableInert; + var disableUpgradeEnabled = Polymer.Settings.disableUpgradeEnabled; Polymer.Annotations = { @@ -370,11 +370,10 @@ node.setAttribute(origName, ''); } // Remove annotation - if (inertEnabled && origName === 'is-inert') { - node.setAttribute('is-inert', ''); - } else { - node.removeAttribute(origName); + if (disableUpgradeEnabled && name === 'disable-upgrade') { + node.setAttribute(name, ''); } + node.removeAttribute(origName); // Case hackery: attributes are lower-case, but bind targets // (properties) are case sensitive. Gambit is to map dash-case to // camel-case: `foo-bar` becomes `fooBar`. diff --git a/src/lib/base.html b/src/lib/base.html index 726e54cdd3..a6c53a3b14 100644 --- a/src/lib/base.html +++ b/src/lib/base.html @@ -64,14 +64,16 @@ }, createdCallback: function() { - if (Polymer.Settings.enableInert && this.hasAttribute('is-inert')) { - this.__data__ = { - isInert: true - }; - this._propertySetter = inertPropertySetter; - } else { - this.__initialize(); + if (Polymer.Settings.disableUpgradeEnabled) { + if (this.hasAttribute('disable-upgrade')) { + this._propertySetter = disableUpgradePropertySetter; + this.__data__ = {}; + return; + } else { + this.__hasInitialized = true; + } } + this.__initialize(); }, __initialize: function() { @@ -299,30 +301,23 @@ Polymer.Base = Polymer.Base.chainObject(Polymer.Base, HTMLElement.prototype); Polymer.BaseDescriptors = {}; - if (Polymer.Settings.enableInert) { + var disableUpgradePropertySetter; + if (Polymer.Settings.disableUpgradeEnabled) { - var inertPropertySetter = function(property, value) { - this.__data__[property] = value; + var origAttributeChangedCallback = Polymer.Base.attributeChangedCallback; + Polymer.Base.attributeChangedCallback = function(name, oldValue, newValue) { + if (!this.__hasInitialized && name === 'disable-upgrade') { + this.__hasInitialized = true; + this._propertySetter = Polymer.Bind._modelApi._propertySetter; + this.__initialize(); + } + origAttributeChangedCallback.call(this, name, oldValue, newValue); } - var inertDesc = { - configurable: true, - writeable: true, - set: function(val) { - if (!val && this.isInert) { - this.__data__.isInert = false; - this._propertySetter = Polymer.Bind._modelApi._propertySetter; - this.__initialize(); - this.removeAttribute('is-inert'); - } - }, - get: function() { - return this.__data__.isInert; - } + disableUpgradePropertySetter = function(property, value) { + this.__data__[property] = value; } - Polymer.BaseDescriptors.isInert = inertDesc; - Object.defineProperty(Polymer.Base, 'isInert', inertDesc); } if (window.CustomElements) { diff --git a/test/runner.html b/test/runner.html index 0cb45953d9..f44d0a8c9b 100644 --- a/test/runner.html +++ b/test/runner.html @@ -93,7 +93,7 @@ 'unit/script-after-import-in-head.html', 'unit/globals.html', 'unit/lazy-register.html', - 'unit/element-inertness.html' + 'unit/element-disable-upgrade.html' ]; if (document.body.createShadowRoot) { diff --git a/test/unit/element-inertness.html b/test/unit/element-disable-upgrade.html similarity index 65% rename from test/unit/element-inertness.html rename to test/unit/element-disable-upgrade.html index 882bdb3614..f070c248fe 100644 --- a/test/unit/element-inertness.html +++ b/test/unit/element-disable-upgrade.html @@ -11,10 +11,10 @@ - + - +