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

Convert ha-menu-button to TS #2825

Merged
merged 3 commits into from
Feb 25, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
50 changes: 0 additions & 50 deletions src/components/ha-menu-button.js

This file was deleted.

32 changes: 32 additions & 0 deletions src/components/ha-menu-button.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import "@polymer/paper-icon-button/paper-icon-button";
import { property, TemplateResult, LitElement, html } from "lit-element";
import { fireEvent } from "../common/dom/fire_event";
balloob marked this conversation as resolved.
Show resolved Hide resolved

class HaMenuButton extends LitElement {
@property({ type: Boolean })
public showMenu = false;

@property({ type: Boolean })
public hassio = false;

protected render(): TemplateResult | void {
return html`
<paper-icon-button
.icon=${`${this.hassio ? "hassio" : "hass"}:menu`}
@click=${this._toggleMenu}
></paper-icon-button>
`;
}

// We are not going to use ShadowDOM as we're rendering a single element
// without any CSS used.
protected createRenderRoot(): Element | ShadowRoot {
Copy link
Member

Choose a reason for hiding this comment

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

does this gain us some performance?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, creation of a shadow root has some overhead, because it's an isolated environment. Although I would not be able to give any numbers. Back in our Polymer 1 days, the polyfill was faster than using native ShadowDOM 😱

return this;
}

private _toggleMenu(): void {
fireEvent(this, this.showMenu ? "hass-close-menu" : "hass-open-menu");
}
}

customElements.define("ha-menu-button", HaMenuButton);
balloob marked this conversation as resolved.
Show resolved Hide resolved