Skip to content
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

Removes default for static get styles #456

Merged
merged 4 commits into from
Jan 18, 2019
Merged

Conversation

sorvell
Copy link
Member

@sorvell sorvell commented Jan 17, 2019

Fixes #452.

In addition...

  • Fixes type settings so Array.flat works.
  • Optimization: ensures this.styles is accessed only once per definition. Since this getter generates CSSResults, it should not be run superfluously.

Fixes #452.

In addition...
* Fixes type settings so `Array.flat` works.
* Optimization: ensures `this.styles` is accessed only once per definition. Since this getter generates CSSResults, it should not be run superfluously.
@sorvell sorvell added this to the 1.0.0 milestone Jan 17, 2019
@@ -66,14 +66,15 @@ export class LitElement extends UpdatingElement {
* Array of styles to apply to the element. The styles should be defined
* using the `css` tag function.
*/
static get styles(): CSSResult | CSSResultArray { return []; }
static styles?: CSSResult | CSSResultArray;

private static _styles: CSSResult[]|undefined;

private static get _uniqueStyles(): CSSResult[] {
if (this._styles === undefined) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to be hasOwnProperty for subclassing to work.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to use a own property check on styles too

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

justinfagnani
justinfagnani previously approved these changes Jan 17, 2019
@justinfagnani justinfagnani dismissed their stale review January 17, 2019 23:27

approved too soon :)

@@ -66,14 +66,15 @@ export class LitElement extends UpdatingElement {
* Array of styles to apply to the element. The styles should be defined
* using the `css` tag function.
*/
static get styles(): CSSResult | CSSResultArray { return []; }
static styles?: CSSResult | CSSResultArray;

private static _styles: CSSResult[]|undefined;

private static get _uniqueStyles(): CSSResult[] {
if (this._styles === undefined) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to use a own property check on styles too

const styles = flattenStyles(this.styles);
const userStyles = this.styles;
if (Array.isArray(userStyles)) {
const styles = flattenStyles(userStyles);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider not re-flattening if !this.hasOwnProperty('styles')

Also add TODO to cache CSSResults to avoid creating new stylesheet objects for subclasses that spread super.styles into this.styles

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Contributor

@justinfagnani justinfagnani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update the changelog too

@sorvell sorvell merged commit 23e305d into master Jan 18, 2019
@sorvell sorvell deleted the remove-default-for-styles branch January 18, 2019 01:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants