From c46a38de7c5cd2f0c81145352b189f4cab7e19d9 Mon Sep 17 00:00:00 2001 From: Kevin Schaaf Date: Wed, 20 Jun 2018 17:45:48 -0700 Subject: [PATCH] Add legacy-data-mixin as 1.x->2.x migration aide. Fixes #5262. --- lib/legacy/class.html | 10 +- lib/legacy/legacy-data-mixin.html | 104 +++++++++++ lib/mixins/property-effects.html | 102 +++++------ test/unit/legacy-data.html | 278 ++++++++++++++++++++++++++++++ 4 files changed, 440 insertions(+), 54 deletions(-) create mode 100644 lib/legacy/legacy-data-mixin.html create mode 100644 test/unit/legacy-data.html diff --git a/lib/legacy/class.html b/lib/legacy/class.html index afe838cc57..82349b620b 100644 --- a/lib/legacy/class.html +++ b/lib/legacy/class.html @@ -353,17 +353,21 @@ * * @param {!PolymerInit} info Object containing Polymer metadata and functions * to become class methods. + * @template T + * @param {function(T):T} mixin Optional mixin to apply to legacy base class * @return {function(new:HTMLElement)} Generated class * @memberof Polymer */ - Polymer.Class = function(info) { + Polymer.Class = function(info, mixin) { if (!info) { console.warn('Polymer.Class requires `info` argument'); } - let klass = GenerateClassFromInfo(info, info.behaviors ? + const baseWithBehaviors = info.behaviors ? // note: mixinBehaviors ensures `LegacyElementMixin`. mixinBehaviors(info.behaviors, HTMLElement) : - Polymer.LegacyElementMixin(HTMLElement)); + Polymer.LegacyElementMixin(HTMLElement); + const baseWithMixin = mixin ? mixin(baseWithBehaviors) : baseWithBehaviors; + const klass = GenerateClassFromInfo(info, baseWithMixin); // decorate klass with registration info klass.is = info.is; return klass; diff --git a/lib/legacy/legacy-data-mixin.html b/lib/legacy/legacy-data-mixin.html new file mode 100644 index 0000000000..32ad88c941 --- /dev/null +++ b/lib/legacy/legacy-data-mixin.html @@ -0,0 +1,104 @@ + + + + + diff --git a/lib/mixins/property-effects.html b/lib/mixins/property-effects.html index de92b17c4a..8cb808d6fa 100644 --- a/lib/mixins/property-effects.html +++ b/lib/mixins/property-effects.html @@ -814,7 +814,7 @@ let context = inst._methodHost || inst; let fn = context[info.methodName]; if (fn) { - let args = marshalArgs(inst.__data, info.args, property, props); + let args = inst._marshalArgs(info.args, property, props); return fn.apply(context, args); } else if (!info.dynamicFn) { console.warn('method `' + info.methodName + '` not defined'); @@ -970,56 +970,6 @@ return a; } - /** - * Gather the argument values for a method specified in the provided array - * of argument metadata. - * - * The `path` and `value` arguments are used to fill in wildcard descriptor - * when the method is being called as a result of a path notification. - * - * @param {Object} data Instance data storage object to read properties from - * @param {!Array} args Array of argument metadata - * @param {string} path Property/path name that triggered the method effect - * @param {Object} props Bag of current property changes - * @return {Array<*>} Array of argument values - * @private - */ - function marshalArgs(data, args, path, props) { - let values = []; - for (let i=0, l=args.length; i} args Array of argument metadata + * @param {string} path Property/path name that triggered the method effect + * @param {Object} props Bag of current property changes + * @return {Array<*>} Array of argument values + * @private + */ + _marshalArgs(args, path, props) { + const data = this.__data; + let values = []; + for (let i=0, l=args.length; i + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +