mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-26 02:36:37 +00:00
Make setView not async (#3274)
This commit is contained in:
parent
1add5077af
commit
d609155022
@ -57,8 +57,6 @@ import { computeRTLDirection } from "../../common/util/compute_rtl";
|
|||||||
const CSS_CACHE = {};
|
const CSS_CACHE = {};
|
||||||
const JS_CACHE = {};
|
const JS_CACHE = {};
|
||||||
|
|
||||||
let loadedUnusedEntities = false;
|
|
||||||
|
|
||||||
class HUIRoot extends LitElement {
|
class HUIRoot extends LitElement {
|
||||||
@property() public hass?: HomeAssistant;
|
@property() public hass?: HomeAssistant;
|
||||||
@property() public lovelace?: Lovelace;
|
@property() public lovelace?: Lovelace;
|
||||||
@ -441,7 +439,8 @@ class HUIRoot extends LitElement {
|
|||||||
if (force && newSelectView === undefined) {
|
if (force && newSelectView === undefined) {
|
||||||
newSelectView = this._curView;
|
newSelectView = this._curView;
|
||||||
}
|
}
|
||||||
this._selectView(newSelectView, force);
|
// Will allow for ripples to start rendering
|
||||||
|
afterNextRender(() => this._selectView(newSelectView, force));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -565,10 +564,7 @@ class HUIRoot extends LitElement {
|
|||||||
scrollToTarget(this, this._layout.header.scrollTarget);
|
scrollToTarget(this, this._layout.header.scrollTarget);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _selectView(
|
private _selectView(viewIndex: HUIRoot["_curView"], force: boolean): void {
|
||||||
viewIndex: HUIRoot["_curView"],
|
|
||||||
force: boolean
|
|
||||||
): Promise<void> {
|
|
||||||
if (!force && this._curView === viewIndex) {
|
if (!force && this._curView === viewIndex) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -589,15 +585,16 @@ class HUIRoot extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (viewIndex === "hass-unused-entities") {
|
if (viewIndex === "hass-unused-entities") {
|
||||||
if (!loadedUnusedEntities) {
|
|
||||||
loadedUnusedEntities = true;
|
|
||||||
await import(/* webpackChunkName: "hui-unused-entities" */ "./hui-unused-entities");
|
|
||||||
}
|
|
||||||
const unusedEntities = document.createElement("hui-unused-entities");
|
const unusedEntities = document.createElement("hui-unused-entities");
|
||||||
|
// Wait for promise to resolve so that the element has been upgraded.
|
||||||
|
import(/* webpackChunkName: "hui-unused-entities" */ "./hui-unused-entities").then(
|
||||||
|
() => {
|
||||||
unusedEntities.setConfig(this.config);
|
unusedEntities.setConfig(this.config);
|
||||||
unusedEntities.hass = this.hass!;
|
unusedEntities.hass = this.hass!;
|
||||||
|
}
|
||||||
|
);
|
||||||
root.style.background = this.config.background || "";
|
root.style.background = this.config.background || "";
|
||||||
root.appendChild(unusedEntities);
|
root.append(unusedEntities);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -612,8 +609,6 @@ class HUIRoot extends LitElement {
|
|||||||
if (!force && this._viewCache![viewIndex]) {
|
if (!force && this._viewCache![viewIndex]) {
|
||||||
view = this._viewCache![viewIndex];
|
view = this._viewCache![viewIndex];
|
||||||
} else {
|
} else {
|
||||||
await new Promise((resolve) => afterNextRender(resolve));
|
|
||||||
|
|
||||||
if (viewConfig.panel && viewConfig.cards && viewConfig.cards.length > 0) {
|
if (viewConfig.panel && viewConfig.cards && viewConfig.cards.length > 0) {
|
||||||
view = createCardElement(viewConfig.cards[0]);
|
view = createCardElement(viewConfig.cards[0]);
|
||||||
view.isPanel = true;
|
view.isPanel = true;
|
||||||
@ -629,7 +624,7 @@ class HUIRoot extends LitElement {
|
|||||||
view.hass = this.hass;
|
view.hass = this.hass;
|
||||||
root.style.background =
|
root.style.background =
|
||||||
viewConfig.background || this.config.background || "";
|
viewConfig.background || this.config.background || "";
|
||||||
root.appendChild(view);
|
root.append(view);
|
||||||
}
|
}
|
||||||
|
|
||||||
private _loadResources(resources) {
|
private _loadResources(resources) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user