Skip to content

Commit

Permalink
Add a template setter to ElementMixin.
Browse files Browse the repository at this point in the history
Currently, to assign a template to a Polymer element, you need to
override the setter, or call Object.defineProperty.

This also allows users to simply assign the template onto their
constructor.

This is especially useful for TypeScript, which compiles "static
template = foo" to "MyClass.template = foo".
  • Loading branch information
aomarks committed Aug 9, 2018
1 parent 59405b5 commit d27b4a1
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/mixins/element-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ export const ElementMixin = dedupingMixin(base => {
* }
* }
*
* @return {HTMLTemplateElement|string} Template to be stamped
* @return {!HTMLTemplateElement|string} Template to be stamped
*/
static get template() {
if (!this.hasOwnProperty(JSCompiler_renameProperty('_template', this))) {
Expand All @@ -389,6 +389,15 @@ export const ElementMixin = dedupingMixin(base => {
return this._template;
}

/**
* Set the template.
*
* @param {!HTMLTemplateElement|string} value Template to set.
*/
static set template(value) {
this._template = value;
}

/**
* Path matching the url from which the element was imported.
*
Expand Down

0 comments on commit d27b4a1

Please sign in to comment.