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 fbf827d commit 44e4828
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
18 changes: 15 additions & 3 deletions lib/legacy/class.html
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,10 @@
`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 (Polymer.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 @@ -426,6 +426,18 @@
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 (!Polymer.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 @@ -55,6 +55,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 @@ -87,7 +88,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
3 changes: 3 additions & 0 deletions test/unit/behaviors.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@

<script>
HTMLImports.whenReady(function() {

Polymer.setLegacyOptimizations(Boolean(window.location.search.match('legacyOptimizations')));

window.BehaviorA = {
properties: {

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 @@ -1058,7 +1058,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 44e4828

Please sign in to comment.