diff --git a/lib/legacy/class.js b/lib/legacy/class.js index aef7eb1f62..9206907764 100644 --- a/lib/legacy/class.js +++ b/lib/legacy/class.js @@ -10,7 +10,6 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN import { LegacyElementMixin } from './legacy-element-mixin.js'; import { legacyOptimizations } from '../utils/settings.js'; -import {DisableUpgradeMixin} from '../mixins/disable-upgrade-mixin.js'; const lifecycleProps = { attached: true, @@ -81,8 +80,6 @@ export function mixinBehaviors(behaviors, klass) { return GenerateClassFromInfo({}, LegacyElementMixin(klass), behaviors); } -const LegacyElementClass = Polymer.LegacyElementMixin(HTMLElement); - // NOTE: // 1.x // Behaviors were mixed in *in reverse order* and de-duped on the fly. @@ -505,10 +502,9 @@ export const Class = function(info, mixin) { if (!info) { console.warn('Polymer.Class requires `info` argument'); } - let klass = mixin ? mixin(LegacyElementClass) : - LegacyElementClass; + let klass = mixin ? mixin(LegacyElementMixin(HTMLElement)) : + LegacyElementMixin(HTMLElement); klass = GenerateClassFromInfo(info, klass, info.behaviors); - klass = DisableUpgradeMixin(klass); // decorate klass with registration info klass.is = klass.prototype.is = info.is; return klass; diff --git a/lib/mixins/disable-upgrade-mixin.js b/lib/mixins/disable-upgrade-mixin.js index 035c4a7d3f..b7f46486e2 100644 --- a/lib/mixins/disable-upgrade-mixin.js +++ b/lib/mixins/disable-upgrade-mixin.js @@ -7,21 +7,22 @@ The complete set of contributors may be found at http://polymer.github.io/CONTRI Code distributed by Google as part of the polymer project is also subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt */ +import { ElementMixin } from './element-mixin.js'; -const DISABLE_UPGRADE = 'disable-upgrade'; +import { dedupingMixin } from '../utils/mixin.js'; + +const DISABLED_ATTR = 'disable-upgrade'; /** * Element class mixin that allows the element to boot up in a non-enabled * state when the `disable-upgrade` attribute is present. This mixin is * designed to be used with element classes like PolymerElement that perform * initial startup work when they are first connected. When the - * `disable-upgrade` attribute is removed, the element - * boots up and "enables" as it otherwise would. - * - * For legacy elements, it also prevents the `created` method from being called - * and event listeners from being added. + * `disable-upgrade` attribute is removed, if the element is connected, it + * boots up and "enables" as it otherwise would; if it is not connected, the + * element boots up when it is next connected. * - * Using `disable-upgrade` with Polymer.Element prevents any data propagation + * Using `disable-upgrade` with PolymerElement prevents any data propagation * to the element, any element DOM from stamping, or any work done in * connected/disconnctedCallback from occuring, but it does not prevent work * done in the element constructor. @@ -34,28 +35,33 @@ const DISABLE_UPGRADE = 'disable-upgrade'; * * @mixinFunction * @polymer - * @appliesMixin Polymer.ElementMixin - * @memberof Polymer - * @param {Object} base base class on which to apply mixin - * @return {Object} class with mixin applied + * @appliesMixin ElementMixin */ -export const DisableUpgradeMixin = (base) => { +export const DisableUpgradeMixin = dedupingMixin((base) => { + + /** + * @constructor + * @extends {base} + * @implements {Polymer_ElementMixin} + * @private + */ + const superClass = ElementMixin(base); /** * @polymer * @mixinClass * @implements {Polymer_DisableUpgradeMixin} */ - class DisableUpgradeClass extends base { + class DisableUpgradeClass extends superClass { /** @override */ static get observedAttributes() { - return super.observedAttributes.concat(DISABLE_UPGRADE); + return super.observedAttributes.concat(DISABLED_ATTR); } /** @override */ attributeChangedCallback(name, old, value, namespace) { - if (name == DISABLE_UPGRADE) { + if (name == DISABLED_ATTR) { if (!this.__dataEnabled && value == null && this.isConnected) { super.connectedCallback(); } @@ -64,16 +70,18 @@ export const DisableUpgradeMixin = (base) => { } } - // disable while `disable-upgrade` is on - created() {} - - // disable while `disable-upgrade` is on - _applyListeners() {} + /* + NOTE: cannot gate on attribute because this is called before + attributes are delivered. Therefore, we stub this out and + call `super._initializeProperties()` manually. + */ + /** @override */ + _initializeProperties() {} // prevent user code in connected from running /** @override */ connectedCallback() { - if (this.__dataEnabled || !this.hasAttribute(DISABLE_UPGRADE)) { + if (this.__dataEnabled || !this.hasAttribute(DISABLED_ATTR)) { super.connectedCallback(); } } @@ -81,19 +89,11 @@ export const DisableUpgradeMixin = (base) => { // prevent element from turning on properties /** @override */ _enableProperties() { - if (!this.__dataEnabled) { - if (!this.hasAttribute(DISABLE_UPGRADE)) { - // When enabling, run previously disabled lifecycle. - // NOTE: This alters the timing of disabled lifecycle for all - // elements that support `disable-upgrade` - if (super.created) { - super.created(); - } - if (super._applyListeners) { - super._applyListeners(); - } - super._enableProperties(); + if (!this.hasAttribute(DISABLED_ATTR)) { + if (!this.__dataEnabled) { + super._initializeProperties(); } + super._enableProperties(); } } @@ -109,4 +109,4 @@ export const DisableUpgradeMixin = (base) => { return DisableUpgradeClass; -}; +}); diff --git a/lib/mixins/property-effects.js b/lib/mixins/property-effects.js index dd18e87479..ac85472154 100644 --- a/lib/mixins/property-effects.js +++ b/lib/mixins/property-effects.js @@ -39,8 +39,6 @@ const TYPES = { /** @const {RegExp} */ const capitalAttributeRegex = /[A-Z]/; -const DISABLE_UPGRADE = 'disable-upgrade'; - /** * @typedef {{ * name: (string | undefined), @@ -2552,9 +2550,6 @@ export const PropertyEffects = dedupingMixin(superClass => { } node.setAttribute(name, literal); } - if (kind == 'attribute' && name == DISABLE_UPGRADE) { - node.setAttribute(DISABLE_UPGRADE, ''); - } // Clear attribute before removing, since IE won't allow removing // `value` attribute if it previously had a value (can't // unconditionally set '' before removing since attributes with `$` diff --git a/test/unit/disable-upgrade.html b/test/unit/disable-upgrade.html index 7b7cd702f6..1c1fc78d7e 100644 --- a/test/unit/disable-upgrade.html +++ b/test/unit/disable-upgrade.html @@ -232,6 +232,9 @@

[[prop]]

}); test('elements call `registered` as expected with `disable-upgrade`', function() { + assert.notOk(el.$.disabledRegEl.hasRegistered); + assert.notOk(el.$.disabledRegBoundEl.hasRegistered); + el.enable(); assert.ok(el.$.disabledRegEl.hasRegistered); assert.ok(el.$.disabledRegBoundEl.hasRegistered); });