Skip to content

Commit 4f22303

Browse files
author
Steven Orvell
committed
Adds legacyOptimizations flag
Set using `Polymer.setLegacyOptimizations(true)`. This flag enables optimizaitons including, always stripping whitespace from templates and avoiding cloning element templates (assumes no inheritance is used) Also re-enables dir-mixin.
1 parent 7251a3a commit 4f22303

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

lib/mixins/dir-mixin.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@
7979
* @memberof Polymer
8080
*/
8181
Polymer.DirMixin = Polymer.dedupingMixin((base) => {
82-
return base;
8382

8483
if (!observer) {
8584
getRTL();

lib/mixins/element-mixin.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,8 @@
314314
let t = document.createElement('template');
315315
t.innerHTML = template;
316316
template = t;
317-
// } else {
318-
// template = template.cloneNode(true);
317+
} else if (!Polymer.legacyOptimizations) {
318+
template = template.cloneNode(true);
319319
}
320320
}
321321

@@ -409,7 +409,7 @@
409409
* The `importPath` property is also set on element instances and can be
410410
* used to create bindings relative to the import path.
411411
*
412-
* For elements defined in ES modules, users should implement
412+
* For elements defined in ES modules, users should implement
413413
* `static get importMeta() { return import.meta; }`, and the default
414414
* implementation of `importPath` will return `import.meta.url`'s path.
415415
* For elements defined in HTML imports, this getter will return the path
@@ -428,7 +428,7 @@
428428
this._importPath = Polymer.ResolveUrl.pathFromUrl(meta.url);
429429
} else {
430430
const module = Polymer.DomModule && Polymer.DomModule.import(/** @type {PolymerElementConstructor} */ (this).is);
431-
this._importPath = (module && module.assetpath) ||
431+
this._importPath = (module && module.assetpath) ||
432432
Object.getPrototypeOf(/** @type {PolymerElementConstructor}*/ (this).prototype).constructor.importPath;
433433
}
434434
}

lib/mixins/template-stamp.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,9 @@
203203
if (!template._templateInfo) {
204204
let templateInfo = template._templateInfo = {};
205205
templateInfo.nodeInfoList = [];
206-
templateInfo.stripWhiteSpace = true;
207-
// (outerTemplateInfo && outerTemplateInfo.stripWhiteSpace) ||
208-
// template.hasAttribute('strip-whitespace');
206+
templateInfo.stripWhiteSpace = Polymer.legacyOptimizations ||
207+
(outerTemplateInfo && outerTemplateInfo.stripWhiteSpace) ||
208+
template.hasAttribute('strip-whitespace');
209209
this._parseTemplateContent(template, templateInfo, {parent: null});
210210
}
211211
return template._templateInfo;

lib/utils/settings.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,5 +114,19 @@
114114
Polymer.setPassiveTouchGestures = function(usePassive) {
115115
Polymer.passiveTouchGestures = usePassive;
116116
};
117+
118+
let legacyOptimizations = false;
119+
Polymer.legacyOptimizations = legacyOptimizations;
120+
/**
121+
* Sets `legacyOptimizations` globally for all elements. Enables
122+
* optimizations when only legacy Polymer() style elements are used.
123+
*
124+
* @memberof Polymer
125+
* @param {boolean} useLegacyOptimizations enable or disable legacy optimizations globally.
126+
* @return {void}
127+
*/
128+
Polymer.setLegacyOptimizations = function(useLegacyOptimizations) {
129+
Polymer.legacyOptimizations = useLegacyOptimizations;
130+
};
117131
})();
118132
</script>

0 commit comments

Comments
 (0)