Skip to content

Commit

Permalink
Adds legacyOptimizations flag
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Steven Orvell committed Oct 31, 2018
1 parent 7251a3a commit 4f22303
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
1 change: 0 additions & 1 deletion lib/mixins/dir-mixin.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@
* @memberof Polymer
*/
Polymer.DirMixin = Polymer.dedupingMixin((base) => {
return base;

if (!observer) {
getRTL();
Expand Down
8 changes: 4 additions & 4 deletions lib/mixins/element-mixin.html
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,8 @@
let t = document.createElement('template');
t.innerHTML = template;
template = t;
// } else {
// template = template.cloneNode(true);
} else if (!Polymer.legacyOptimizations) {
template = template.cloneNode(true);
}
}

Expand Down Expand Up @@ -409,7 +409,7 @@
* The `importPath` property is also set on element instances and can be
* used to create bindings relative to the import path.
*
* For elements defined in ES modules, users should implement
* For elements defined in ES modules, users should implement
* `static get importMeta() { return import.meta; }`, and the default
* implementation of `importPath` will return `import.meta.url`'s path.
* For elements defined in HTML imports, this getter will return the path
Expand All @@ -428,7 +428,7 @@
this._importPath = Polymer.ResolveUrl.pathFromUrl(meta.url);
} else {
const module = Polymer.DomModule && Polymer.DomModule.import(/** @type {PolymerElementConstructor} */ (this).is);
this._importPath = (module && module.assetpath) ||
this._importPath = (module && module.assetpath) ||
Object.getPrototypeOf(/** @type {PolymerElementConstructor}*/ (this).prototype).constructor.importPath;
}
}
Expand Down
6 changes: 3 additions & 3 deletions lib/mixins/template-stamp.html
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,9 @@
if (!template._templateInfo) {
let templateInfo = template._templateInfo = {};
templateInfo.nodeInfoList = [];
templateInfo.stripWhiteSpace = true;
// (outerTemplateInfo && outerTemplateInfo.stripWhiteSpace) ||
// template.hasAttribute('strip-whitespace');
templateInfo.stripWhiteSpace = Polymer.legacyOptimizations ||
(outerTemplateInfo && outerTemplateInfo.stripWhiteSpace) ||
template.hasAttribute('strip-whitespace');
this._parseTemplateContent(template, templateInfo, {parent: null});
}
return template._templateInfo;
Expand Down
14 changes: 14 additions & 0 deletions lib/utils/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -114,5 +114,19 @@
Polymer.setPassiveTouchGestures = function(usePassive) {
Polymer.passiveTouchGestures = usePassive;
};

let legacyOptimizations = false;
Polymer.legacyOptimizations = legacyOptimizations;
/**
* Sets `legacyOptimizations` globally for all elements. Enables
* optimizations when only legacy Polymer() style elements are used.
*
* @memberof Polymer
* @param {boolean} useLegacyOptimizations enable or disable legacy optimizations globally.
* @return {void}
*/
Polymer.setLegacyOptimizations = function(useLegacyOptimizations) {
Polymer.legacyOptimizations = useLegacyOptimizations;
};
})();
</script>

0 comments on commit 4f22303

Please sign in to comment.