Polymer / polymer

Our original Web Component library.
https://polymer-library.polymer-project.org/
BSD 3-Clause "New" or "Revised" License
22.04k stars 2.01k forks source link

Add support for lazy template function in legacy _template field #5660

Closed kevinpschaaf closed 4 years ago

kevinpschaaf commented 4 years ago

Description

The static get template() { ... } field on Polymer 3's class syntax is lazy; i.e. it won't invoke the function (which normally does the template parsing) until the element is instanced, which is a performance optimization when element definitions are loaded but not immediately instanced.

However the legacy Polymer({ _template: ... }) field basically requires providing a concrete template. Unfortunately, implementing a get _template() { ... } getter is not sufficient, since for legacy reasons Polymer sets the finalized template back to prototype._template, hence it also needs a setter that overrides the original value. This becomes rather cumbersome to author.

This issue is to make a minor change to the legacy Polymer template processing to allow setting a function to _template on the Polymer info object. The type of the value will be checked, and if it is a function it will be run once and the return value will be used.

Versions