From 6dd3456940974b9c9e1f52d9318641dc9e425e1f Mon Sep 17 00:00:00 2001 From: Kevin Schaaf Date: Thu, 1 Nov 2018 23:15:56 -0700 Subject: [PATCH] Apply LegacyDataMixin to TemplatizeInstanceBase. Fixes #5422 --- lib/legacy/legacy-data-mixin.js | 10 ++++++ lib/utils/templatize.js | 4 +++ test/unit/legacy-data.html | 58 +++++++++++++++++++++++++++++++-- 3 files changed, 69 insertions(+), 3 deletions(-) diff --git a/lib/legacy/legacy-data-mixin.js b/lib/legacy/legacy-data-mixin.js index 5aee1e0209..e21e098917 100644 --- a/lib/legacy/legacy-data-mixin.js +++ b/lib/legacy/legacy-data-mixin.js @@ -11,6 +11,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN import { Class } from './class.js'; import { Polymer } from '../../polymer-legacy.js'; import { dedupingMixin } from '../utils/mixin.js'; +import { templatize } from '../utils/templatize.js'; const UndefinedArgumentError = class extends Error { constructor(message, arg) { @@ -149,5 +150,14 @@ Polymer.Class = (info, mixin) => Class(info, LegacyDataMixin(superClass) ); +// Apply LegacyDataMixin to Templatizer instances as well, and defer +// runtime switch to the root's host (_methodHost) +templatize.mixin = + dedupingMixin(superClass => class extends LegacyDataMixin(superClass) { + get _legacyUndefinedCheck() { + return this._methodHost && this._methodHost._legacyUndefinedCheck; + } + }); + console.info('LegacyDataMixin will be applied to all legacy elements.\n' + 'Set `_legacyUndefinedCheck: true` on element class to enable.'); diff --git a/lib/utils/templatize.js b/lib/utils/templatize.js index a28bae35c6..14b5eeb6fe 100644 --- a/lib/utils/templatize.js +++ b/lib/utils/templatize.js @@ -334,6 +334,10 @@ function createTemplatizerClass(template, templateInfo, options) { // Anonymous class created by the templatize let base = options.mutableData ? MutableTemplateInstanceBase : TemplateInstanceBase; + // Affordance for global mixins onto TemplatizeInstance + if (templatize.mixin) { + base = templatize.mixin(base); + } /** * @constructor * @extends {base} diff --git a/test/unit/legacy-data.html b/test/unit/legacy-data.html index 3747c9f561..353efd1269 100644 --- a/test/unit/legacy-data.html +++ b/test/unit/legacy-data.html @@ -24,6 +24,9 @@
+ + +