From 7f2fcb183f0439d9ac404fc5a59322b0fc28e672 Mon Sep 17 00:00:00 2001 From: Kevin Schaaf Date: Wed, 31 Oct 2018 10:58:49 -0700 Subject: [PATCH] Update types. --- externs/closure-types.js | 20 +++++++++- types/lib/legacy/legacy-data-mixin.d.ts | 53 ++++++++++++++++++++----- 2 files changed, 63 insertions(+), 10 deletions(-) diff --git a/externs/closure-types.js b/externs/closure-types.js index 62e86e785d..37f4a422b2 100644 --- a/externs/closure-types.js +++ b/externs/closure-types.js @@ -1412,4 +1412,22 @@ Polymer_DisableUpgradeMixin.prototype.connectedCallback = function(){}; /** * @override */ -Polymer_DisableUpgradeMixin.prototype.disconnectedCallback = function(){}; \ No newline at end of file +Polymer_DisableUpgradeMixin.prototype.disconnectedCallback = function(){}; +/** +* @interface +*/ +function Polymer_LegacyDataMixin(){} +/** +* @param {string} property Property that should trigger the effect +* @param {string} type Effect type, from this.PROPERTY_EFFECT_TYPES +* @param {Object=} effect Effect metadata object +* @return {void} +*/ +Polymer_LegacyDataMixin.prototype._addPropertyEffect = function(property, type, effect){}; +/** +* @param {Object} templateInfo Template metadata to add effect to +* @param {string} prop Property that should trigger the effect +* @param {Object=} effect Effect metadata object +* @return {void} +*/ +Polymer_LegacyDataMixin._addTemplatePropertyEffect = function(templateInfo, prop, effect){}; \ No newline at end of file diff --git a/types/lib/legacy/legacy-data-mixin.d.ts b/types/lib/legacy/legacy-data-mixin.d.ts index 785df30365..7c8bda05df 100644 --- a/types/lib/legacy/legacy-data-mixin.d.ts +++ b/types/lib/legacy/legacy-data-mixin.d.ts @@ -9,21 +9,56 @@ */ /// +/// /// -declare class UndefinedArgumentError { - constructor(message: any); +declare class UndefinedArgumentError extends Error { + constructor(message: any, arg: any); } -declare class LegacyDataMixin { +declare namespace Polymer { + /** - * Overrides `Polyer.PropertyEffects` to wrap effect functions to - * catch `UndefinedArgumentError`s and warn. + * Mixin to selectively add back Polymer 1.x's `undefined` rules + * governing when observers & computing functions run based + * on all arguments being defined (reference https://www.polymer-project.org/1.0/docs/devguide/observers#multi-property-observers). + * + * When loaded, all legacy elements (defined with `Polymer({...})`) + * will have the mixin applied. The mixin only restores legacy data handling + * if `_legacyUndefinedCheck: true` is set on the element's prototype. * - * @param property Property that should trigger the effect - * @param type Effect type, from this.PROPERTY_EFFECT_TYPES - * @param effect Effect metadata object + * This mixin is intended for use to help migration from Polymer 1.x to + * 2.x+ by allowing legacy code to work while identifying observers and + * computing functions that need undefined checks to work without + * the mixin in Polymer 2. */ - _addPropertyEffect(property: string, type: string, effect?: object|null): void; + function LegacyDataMixin {}>(base: T): T & LegacyDataMixinConstructor; + + interface LegacyDataMixinConstructor { + new(...args: any[]): LegacyDataMixin; + + /** + * Overrides `Polyer.PropertyEffects` to wrap effect functions to + * catch `UndefinedArgumentError`s and warn. + * + * @param templateInfo Template metadata to add effect to + * @param prop Property that should trigger the effect + * @param effect Effect metadata object + */ + _addTemplatePropertyEffect(templateInfo: object|null, prop: string, effect?: object|null): void; + } + + interface LegacyDataMixin { + + /** + * Overrides `Polyer.PropertyEffects` to wrap effect functions to + * catch `UndefinedArgumentError`s and warn. + * + * @param property Property that should trigger the effect + * @param type Effect type, from this.PROPERTY_EFFECT_TYPES + * @param effect Effect metadata object + */ + _addPropertyEffect(property: string, type: string, effect?: object|null): void; + } }