Do lazy behavior copying only when legacyOptimizations is set

This commit is contained in:
Steven Orvell
2018-11-09 18:48:53 -08:00
parent fbf827d9c7
commit 44e4828796
4 changed files with 20 additions and 5 deletions
+15 -3
View File
@@ -297,10 +297,10 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
`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++) {
@@ -426,6 +426,18 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
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;
+2 -1
View File
@@ -55,6 +55,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
'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',
@@ -87,7 +88,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
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), []);
}
+3
View File
@@ -30,6 +30,9 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
<script>
HTMLImports.whenReady(function() {
Polymer.setLegacyOptimizations(Boolean(window.location.search.match('legacyOptimizations')));
window.BehaviorA = {
properties: {
-1
View File
@@ -1058,7 +1058,6 @@ HTMLImports.whenReady(function() {
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'));