Skip to content

Commit

Permalink
Merge pull request #5423 from Polymer/5422-ldm-templatizer-fix
Browse files Browse the repository at this point in the history
Apply LegacyDataMixin to TemplatizeInstanceBase. Fixes #5422
  • Loading branch information
kevinpschaaf authored Nov 27, 2018
2 parents a7c861b + c23ff5e commit 56fc683
Show file tree
Hide file tree
Showing 4 changed files with 195 additions and 129 deletions.
10 changes: 10 additions & 0 deletions lib/legacy/legacy-data-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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.');
4 changes: 4 additions & 0 deletions lib/utils/templatize.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
Loading

0 comments on commit 56fc683

Please sign in to comment.