-
Notifications
You must be signed in to change notification settings - Fork 320
Render any value returned by #render.
#712
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
27aa4e3
1af58d7
c5235cc
cb57530
b257fdb
9812a9f
2e5b725
33df4aa
ded5f63
81ccca3
7cc0084
415dfda
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,8 +11,7 @@ | |
| * subject to an additional IP rights grant found at | ||
| * http://polymer.github.io/PATENTS.txt | ||
| */ | ||
| import {TemplateResult} from 'lit-html'; | ||
| import {render} from 'lit-html/lib/shady-render.js'; | ||
| import {render, ShadyRenderOptions} from 'lit-html/lib/shady-render.js'; | ||
|
|
||
| import {PropertyValues, UpdatingElement} from './lib/updating-element.js'; | ||
|
|
||
|
|
@@ -45,15 +44,17 @@ export class LitElement extends UpdatingElement { | |
| * optimizations. See updating-element.ts for more information. | ||
| */ | ||
| protected static['finalized'] = true; | ||
|
|
||
| /** | ||
| * Render method used to render the lit-html TemplateResult to the element's | ||
| * DOM. | ||
| * @param {TemplateResult} Template to render. | ||
| * @param {Element|DocumentFragment} Node into which to render. | ||
| * @param {String} Element name. | ||
| * Render method used to render the value to the element's DOM. | ||
| * @param result The value to render. | ||
| * @param container Node into which to render. | ||
| * @param options Element name. | ||
| * @nocollapse | ||
| */ | ||
| static render = render; | ||
| static render: | ||
| (result: unknown, container: Element|DocumentFragment, | ||
| options: ShadyRenderOptions) => void = render; | ||
|
|
||
| /** | ||
| * Array of styles to apply to the element. The styles should be defined | ||
|
|
@@ -194,14 +195,11 @@ export class LitElement extends UpdatingElement { | |
| */ | ||
| protected update(changedProperties: PropertyValues) { | ||
| super.update(changedProperties); | ||
| const templateResult = this.render() as unknown; | ||
| if (templateResult instanceof TemplateResult) { | ||
| (this.constructor as typeof LitElement) | ||
| .render( | ||
| templateResult, | ||
| this.renderRoot, | ||
| {scopeName: this.localName, eventContext: this}); | ||
| } | ||
| (this.constructor as typeof LitElement) | ||
| .render( | ||
| this.render(), | ||
| this.renderRoot, | ||
| {scopeName: this.localName, eventContext: this}); | ||
| // When native Shadow DOM is used but adoptedStyles are not supported, | ||
| // insert styling after rendering to ensure adoptedStyles have highest | ||
| // priority. | ||
|
|
@@ -216,10 +214,12 @@ export class LitElement extends UpdatingElement { | |
| } | ||
|
|
||
| /** | ||
| * Invoked on each update to perform rendering tasks. This method must return | ||
| * a lit-html TemplateResult. Setting properties inside this method will *not* | ||
| * trigger the element to update. | ||
| * Invoked on each update to perform rendering tasks. This method may return | ||
| * any value renderable by lit-html's NodePart - typically a TemplateResult. | ||
| * Setting properties inside this method will *not* trigger the element to | ||
| * update. | ||
| */ | ||
| protected render(): TemplateResult|void { | ||
| protected render(): unknown { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you elide the return if you type this as
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't seem like it:
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a shame to add non-observable, non-type annotation code to satisfy the type-checker. Can we cast our way out of this?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know how I would cast the function in place since class syntax isn't expression based (and I assume we don't want to bind it / remove it from the prototype by making it a property), so I tried pulling it out of the class as this: LitElement.prototype.render = function() {} as () => unknown;But then I get another couple of errors that seem like TS is no longer recognizing that I'm not familiar with pre-classes TS, so maybe that's not the right way to do it?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (from offline) I'm going to leave the |
||
| return undefined; | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.