Skip to content

Commit

Permalink
Use hasupdated
Browse files Browse the repository at this point in the history
  • Loading branch information
piitaya committed Jun 27, 2024
1 parent 43d5daa commit b71888b
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions src/panels/lovelace/cards/hui-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,27 +124,30 @@ export class HuiCard extends ReactiveElement {
this._updateVisibility();
}

protected update(changedProps: PropertyValues<typeof this>) {
super.update(changedProps);
protected willUpdate(changedProps: PropertyValues<typeof this>): void {
super.willUpdate(changedProps);

if (!this._element) {
this.build();
}
}

if (changedProps.has("config")) {
const oldConfig = changedProps.get("config");
if (this.config && oldConfig && this.config !== oldConfig) {
const typeChanged = this.config.type !== oldConfig.type;
if (typeChanged) {
this._buildElement(this.config);
} else {
this._element?.setConfig(this.config);
fireEvent(this, "card-updated");
}
}
}
protected update(changedProps: PropertyValues<typeof this>) {
super.update(changedProps);

if (this._element) {
if (changedProps.has("config") && this.hasUpdated) {
const oldConfig = changedProps.get("config");
if (this.config !== oldConfig && this.config) {
const typeChanged = this.config?.type !== oldConfig?.type;
if (typeChanged) {
this._buildElement(this.config);
} else {
this._element?.setConfig(this.config);
fireEvent(this, "card-updated");
}
}
}
if (changedProps.has("hass")) {
try {
if (this.hass) {
Expand Down

0 comments on commit b71888b

Please sign in to comment.