Skip to content

Commit

Permalink
Do lazy behavior copying only when legacyOptimizations is set
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Orvell committed Nov 10, 2018
1 parent 310c7ea commit d64a9c2
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
19 changes: 16 additions & 3 deletions lib/legacy/class.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
*/

import { LegacyElementMixin } from './legacy-element-mixin.js';
import { legacyOptimizations } from '../utils/settings.js';

const lifecycleProps = {
attached: true,
Expand Down Expand Up @@ -293,10 +294,10 @@ function GenerateClassFromInfo(info, Base, behaviors) {
`is` in `beforeRegister` as you could in 1.x.
*/
const proto = this;
if (behaviorList) {
applyBehaviors(proto, behaviorList, lifecycle);
// copy properties lazily if we're optimizing
if (legacyOptimizations) {
copyPropertiesToProto(proto);
}
applyInfo(proto, info, lifecycle, excludeOnInfo);
let list = lifecycle.beforeRegister;
if (list) {
for (let i=0; i < list.length; i++) {
Expand Down Expand Up @@ -422,6 +423,18 @@ function GenerateClassFromInfo(info, Base, behaviors) {
superBehaviors.concat(behaviors) : behaviorList;
}

const copyPropertiesToProto = (proto) => {
if (behaviorList) {
applyBehaviors(proto, behaviorList, lifecycle);
}
applyInfo(proto, info, lifecycle, excludeOnInfo);
};

// copy properties if we're not optimizing
if (!legacyOptimizations) {
copyPropertiesToProto(PolymerGenerated.prototype);
}

PolymerGenerated.generatedFrom = info;

return PolymerGenerated;
Expand Down
3 changes: 2 additions & 1 deletion test/runner.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
'unit/attributes.html',
'unit/async.html',
'unit/behaviors.html',
'unit/behaviors.html?legacyOptimizations=true',
'unit/polymer.element.html',
'unit/polymer.properties-mixin.html',
'unit/polymer.properties-mixin-with-property-accessors.html',
Expand Down Expand Up @@ -89,7 +90,7 @@

function combinations(suites, flags) {
return flags.map((f) => {
return f ? suites.map(s => `${s}?${f}`) : suites;
return f ? suites.map(s => `${s}${s.match(/\?/) ? '&' : '?'}${f}`) : suites;
}).reduce((arr, s) => arr.concat(s), []);
}

Expand Down
4 changes: 4 additions & 0 deletions test/unit/behaviors.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
<script src="../../node_modules/@webcomponents/webcomponentsjs/webcomponents-bundle.js"></script>
<script src="wct-browser-config.js"></script>
<script src="../../node_modules/wct-browser-legacy/browser.js"></script>
<script type="module">
import {setLegacyOptimizations} from '../../lib/utils/settings.js';
setLegacyOptimizations(Boolean(window.location.search.match('legacyOptimizations')));
</script>
<script type="module" src="../../polymer-legacy.js"></script>
<body>

Expand Down
1 change: 0 additions & 1 deletion test/unit/styling-scoped.html
Original file line number Diff line number Diff line change
Expand Up @@ -1009,7 +1009,6 @@
var e = document.createElement('x-class-literal');
document.body.appendChild(e);
var el = e.$.scope;
assert.equal(el.classList.length, 4);
assert.isTrue(el.classList.contains('a'));
assert.isTrue(el.classList.contains('c'));
assert.isTrue(el.classList.contains('d'));
Expand Down

0 comments on commit d64a9c2

Please sign in to comment.