Skip to content

Commit

Permalink
Revert "Manual merge from perf-opt-disable-upgrade branch."
Browse files Browse the repository at this point in the history
This reverts commit 0f022df.
  • Loading branch information
Steven Orvell committed Dec 7, 2018
1 parent 05a7e1c commit c3bd4d6
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 45 deletions.
8 changes: 2 additions & 6 deletions lib/legacy/class.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down
68 changes: 34 additions & 34 deletions lib/mixins/disable-upgrade-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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();
}
Expand All @@ -64,36 +70,30 @@ 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();
}
}

// 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();
}
}

Expand All @@ -109,4 +109,4 @@ export const DisableUpgradeMixin = (base) => {

return DisableUpgradeClass;

};
});
5 changes: 0 additions & 5 deletions lib/mixins/property-effects.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ const TYPES = {
/** @const {RegExp} */
const capitalAttributeRegex = /[A-Z]/;

const DISABLE_UPGRADE = 'disable-upgrade';

/**
* @typedef {{
* name: (string | undefined),
Expand Down Expand Up @@ -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 `$`
Expand Down
3 changes: 3 additions & 0 deletions test/unit/disable-upgrade.html
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@ <h2 id="element">[[prop]]</h2>
});

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);
});
Expand Down

0 comments on commit c3bd4d6

Please sign in to comment.