From 7e74e363ffa6f6b18b5047109b77eb2196740984 Mon Sep 17 00:00:00 2001 From: Daniel Freedman Date: Wed, 21 Feb 2018 12:45:18 -0800 Subject: [PATCH] Ensure DisableUpgradeMixin extends PropertiesMixin --- externs/closure-types.js | 13 +++++----- lib/mixins/disable-upgrade-mixin.html | 28 ++++++++++++++++++--- types/lib/mixins/disable-upgrade-mixin.d.ts | 20 +-------------- 3 files changed, 31 insertions(+), 30 deletions(-) diff --git a/externs/closure-types.js b/externs/closure-types.js index d1f9ec23e5..a4897db637 100644 --- a/externs/closure-types.js +++ b/externs/closure-types.js @@ -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(){}; \ No newline at end of file diff --git a/lib/mixins/disable-upgrade-mixin.html b/lib/mixins/disable-upgrade-mixin.html index b31decfc09..4e7bfb4535 100644 --- a/lib/mixins/disable-upgrade-mixin.html +++ b/lib/mixins/disable-upgrade-mixin.html @@ -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) { @@ -60,9 +74,11 @@ 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(); @@ -70,6 +86,7 @@ } // prevent element from turning on properties + /** @override */ _enableProperties() { if (!this.hasAttribute(DISABLED_ATTR)) { if (!this.__dataEnabled) { @@ -80,15 +97,18 @@ } // only go if "enabled" + /** @override */ disconnectedCallback() { if (this.__dataEnabled) { super.disconnectedCallback(); } } - }; + } - }; + return DisableUpgradeClass; + + }); })(); diff --git a/types/lib/mixins/disable-upgrade-mixin.d.ts b/types/lib/mixins/disable-upgrade-mixin.d.ts index 7431a4c145..471a8462e4 100644 --- a/types/lib/mixins/disable-upgrade-mixin.d.ts +++ b/types/lib/mixins/disable-upgrade-mixin.d.ts @@ -31,7 +31,7 @@ declare namespace Polymer { * * MyClass = Polymer.DisableUpgradeMixin(class extends BaseClass {...}); */ - function DisableUpgradeMixin {}>(base: T): T & DisableUpgradeMixinConstructor; + function DisableUpgradeMixin {}>(base: T): T & DisableUpgradeMixinConstructor & Polymer.PropertiesChangedConstructor; interface DisableUpgradeMixinConstructor { new(...args: any[]): DisableUpgradeMixin; @@ -39,27 +39,9 @@ declare namespace Polymer { 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; } }