Skip to content

Commit

Permalink
Apply mixin to TemplatizeInstance
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinpschaaf committed Oct 31, 2018
1 parent 7f2fcb1 commit 55e9dfd
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/legacy/legacy-data-mixin.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
-->

<link rel="import" href="class.html">
<link rel="import" href="../polymer.html">
<link rel="import" href="../../polymer.html">
<link rel="import" href="../utils/mixin.html">
<link rel="import" href="../utils/templatize.html">

<script>
(function() {
Expand Down Expand Up @@ -154,6 +155,13 @@
Polymer.LegacyDataMixin(superClass)
);

Polymer.Templatize.mixin =
Polymer.dedupingMixin(superClass => class extends Polymer.LegacyDataMixin(superClass) {
get _legacyUndefinedCheck() {
return this._methodHost._legacyUndefinedCheck;
}
});

console.info('LegacyDataMixin will be applied to all legacy elements.\n' +
'Set `_legacyUndefinedCheck: true` to enable.');

Expand Down
4 changes: 4 additions & 0 deletions lib/utils/templatize.html
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,10 @@
// Anonymous class created by the templatize
let base = options.mutableData ?
MutableTemplateInstanceBase : TemplateInstanceBase;
// Affordance for global mixins onto TemplatizeInstance
if (Polymer.Templatize.mixin) {
base = Polymer.Templatize.mixin(base);
}
/**
* @constructor
* @extends {base}
Expand Down
53 changes: 53 additions & 0 deletions test/unit/legacy-data.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
<div id="child"
computed-single="[[computeSingle(inlineSingleDep)]]"
computed-multi="[[computeMulti(inlineMultiDep1, inlineMultiDep2)]]">
<dom-if if>
<template><div id="ifChild" computed-multi="[[computeMulti(inlineMultiIfDep1, inlineMultiIfDep2)]]"></div></template>
</dom-if>
</div>
</template>
<script>
Expand All @@ -40,6 +43,8 @@
inlineSingleDep: String,
inlineMultiDep1: String,
inlineMultiDep2: String,
inlineMultiIfDep1: String,
inlineMultiIfDep2: String,
computedSingle: {
computed: 'computeSingle(computedSingleDep)'
},
Expand Down Expand Up @@ -128,6 +133,18 @@
</template>
</test-fixture>

<test-fixture id="declarative-multi-if-one-computed-inline">
<template>
<x-data inline-multi-if-dep1="b"></x-data>
</template>
</test-fixture>

<test-fixture id="declarative-multi-if-all-computed-inline">
<template>
<x-data inline-multi-if-dep1="b" inline-multi-if-dep2="c"></x-data>
</template>
</test-fixture>

<script>
(function() {

Expand Down Expand Up @@ -156,6 +173,7 @@
el._legacyUndefinedCheck = check;
Object.assign(el, props);
document.body.appendChild(el);
Polymer.flush();
}

teardown(() => {
Expand All @@ -172,6 +190,8 @@
const inlineSingleDep = 'inlineSingleDep';
const inlineMultiDep1 = 'inlineMultiDep1';
const inlineMultiDep2 = 'inlineMultiDep2';
const inlineMultiIfDep1 = 'inlineMultiIfDep1';
const inlineMultiIfDep2 = 'inlineMultiIfDep2';

suite('check disabled', () => {
test('no arguments defined', () => {
Expand Down Expand Up @@ -240,6 +260,16 @@
assertEffects({computeMulti: 1});
assert.equal(el.$.child.computedMulti, '[inlineMultiDep1,inlineMultiDep2]');
});
test('one inline computeMulti argument defined in dom-if', () => {
setupElement(false, {inlineMultiIfDep1});
assertEffects({computeMulti: 1});
assert.equal(el.$$('#ifChild').computedMulti, '[inlineMultiIfDep1,undefined]');
});
test('all inline computeMulti argument defined in dom-if', () => {
setupElement(false, {inlineMultiIfDep1, inlineMultiIfDep2});
assertEffects({computeMulti: 1});
assert.equal(el.$$('#ifChild').computedMulti, '[inlineMultiIfDep1,inlineMultiIfDep2]');
});
});

suite('warn', () => {
Expand Down Expand Up @@ -309,6 +339,16 @@
assertEffects({computeMulti: 1});
assert.equal(el.$.child.computedMulti, '[inlineMultiDep1,inlineMultiDep2]');
});
test('one inline computeMulti argument defined in dom-if', () => {
setupElement(true, {inlineMultiIfDep1});
assertEffects({warn: 1});
assert.equal(el.$$('#ifChild').computedMulti, undefined);
});
test('all inline computeMulti argument defined in dom-if', () => {
setupElement(true, {inlineMultiIfDep1, inlineMultiIfDep2});
assertEffects({computeMulti: 1});
assert.equal(el.$$('#ifChild').computedMulti, '[inlineMultiIfDep1,inlineMultiIfDep2]');
});
});
});

Expand Down Expand Up @@ -361,8 +401,21 @@
});
test('inline all computeMulti defined', () => {
el = fixture('declarative-multi-all-computed-inline');
assertEffects({computeMulti: 1});
assert.equal(el.$.child.computedMulti, '[b,c]');
});
test('one inline computeMulti argument defined in dom-if', () => {
el = fixture('declarative-multi-if-one-computed-inline');
Polymer.flush();
assertEffects({computeMulti: 0, warn: 1});
assert.equal(el.$$('#ifChild').computedMulti, undefined);
});
test('all inline computeMulti argument defined in dom-if', () => {
el = fixture('declarative-multi-if-all-computed-inline');
Polymer.flush();
assertEffects({computeMulti: 1});
assert.equal(el.$$('#ifChild').computedMulti, '[b,c]');
});
});
});

Expand Down

0 comments on commit 55e9dfd

Please sign in to comment.