Skip to content

Commit

Permalink
Ensure DisableUpgradeMixin extends PropertiesMixin
Browse files Browse the repository at this point in the history
  • Loading branch information
dfreedm committed Feb 21, 2018
1 parent b8c66de commit 7e74e36
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 30 deletions.
13 changes: 6 additions & 7 deletions externs/closure-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -1377,27 +1377,26 @@ Polymer_ArraySelectorMixin.prototype.select = function(item){};
Polymer_ArraySelectorMixin.prototype.selectIndex = function(idx){};
/**
* @interface
* @extends {Polymer_PropertiesChanged}
*/
function Polymer_DisableUpgradeMixin(){}
/**
* @param {*} name
* @param {*} old
* @param {*} value
* @override
*/
Polymer_DisableUpgradeMixin.prototype.attributeChangedCallback = function(name, old, value){};
/**
* @return {undefined}
* @override
*/
Polymer_DisableUpgradeMixin.prototype._initializeProperties = function(){};
/**
* @return {undefined}
* @override
*/
Polymer_DisableUpgradeMixin.prototype.connectedCallback = function(){};
/**
* @return {undefined}
* @override
*/
Polymer_DisableUpgradeMixin.prototype._enableProperties = function(){};
/**
* @return {undefined}
* @override
*/
Polymer_DisableUpgradeMixin.prototype.disconnectedCallback = function(){};
28 changes: 24 additions & 4 deletions lib/mixins/disable-upgrade-mixin.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,30 @@
*
* @mixinFunction
* @polymer
* @appliesMixin Polymer.PropertiesChanged
* @memberof Polymer
*/
Polymer.DisableUpgradeMixin = (base) => {
Polymer.DisableUpgradeMixin = Polymer.dedupingMixin((base) => {

return class DisableUpgradeClass extends base {
/**
* @constructor
* @extends {base}
* @implements {Polymer_PropertiesMixin}
*/
const superClass = Polymer.PropertiesMixin(base);
/**
* @polymer
* @mixinClass
* @implements {Polymer_DisableUpgradeMixin}
*/
class DisableUpgradeClass extends superClass {

/** @override */
static get observedAttributes() {
return super.observedAttributes.concat(DISABLED_ATTR);
}

/** @override */
attributeChangedCallback(name, old, value) {
if (name == DISABLED_ATTR) {
if (!this.__dataEnabled && value == null && this.isConnected) {
Expand All @@ -60,16 +74,19 @@
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(DISABLED_ATTR)) {
super.connectedCallback();
}
}

// prevent element from turning on properties
/** @override */
_enableProperties() {
if (!this.hasAttribute(DISABLED_ATTR)) {
if (!this.__dataEnabled) {
Expand All @@ -80,15 +97,18 @@
}

// only go if "enabled"
/** @override */
disconnectedCallback() {
if (this.__dataEnabled) {
super.disconnectedCallback();
}
}

};
}

};
return DisableUpgradeClass;

});

})();

Expand Down
20 changes: 1 addition & 19 deletions types/lib/mixins/disable-upgrade-mixin.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,35 +31,17 @@ declare namespace Polymer {
*
* MyClass = Polymer.DisableUpgradeMixin(class extends BaseClass {...});
*/
function DisableUpgradeMixin<T extends new (...args: any[]) => {}>(base: T): T & DisableUpgradeMixinConstructor;
function DisableUpgradeMixin<T extends new (...args: any[]) => {}>(base: T): T & DisableUpgradeMixinConstructor & Polymer.PropertiesChangedConstructor;

interface DisableUpgradeMixinConstructor {
new(...args: any[]): DisableUpgradeMixin;
}

interface DisableUpgradeMixin {
attributeChangedCallback(name: any, old: any, value: any): void;

/**
* NOTE: cannot gate on attribute because this is called before
* attributes are delivered. Therefore, we stub this out and
* call `super._initializeProperties()` manually.
*/
_initializeProperties(): void;

/**
* prevent user code in connected from running
*/
connectedCallback(): void;

/**
* prevent element from turning on properties
*/
_enableProperties(): void;

/**
* only go if "enabled"
*/
disconnectedCallback(): void;
}
}

0 comments on commit 7e74e36

Please sign in to comment.