-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
20240628.0 #21223
20240628.0 #21223
Changes from all commits
df65038
3b15d26
11d832c
dcd4c39
cbc95a5
4a1087c
d33cf4f
85865af
beec720
18a6f8d
9beb4c3
b81314f
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 |
---|---|---|
|
@@ -31,6 +31,8 @@ export class HuiCard extends ReactiveElement { | |
|
||
@property({ attribute: false }) public hass?: HomeAssistant; | ||
|
||
private _elementConfig?: LovelaceCardConfig; | ||
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. New properties and methods look good, but consider type safety improvements. The introduction of - catch (e: any) {
+ catch (e: Error) { Also applies to: 86-93, 97-97, 147-154 |
||
|
||
public load() { | ||
if (!this.config) { | ||
throw new Error("Cannot build card without config"); | ||
|
@@ -43,9 +45,6 @@ export class HuiCard extends ReactiveElement { | |
private _listeners: MediaQueriesListener[] = []; | ||
|
||
protected createRenderRoot() { | ||
const style = document.createElement("style"); | ||
style.textContent = `hui-card { display: contents }`; | ||
this.append(style); | ||
return this; | ||
} | ||
|
||
|
@@ -84,8 +83,18 @@ export class HuiCard extends ReactiveElement { | |
return this._element?.getLayoutOptions?.() ?? {}; | ||
} | ||
|
||
private _updateElement(config: LovelaceCardConfig) { | ||
if (!this._element) { | ||
return; | ||
} | ||
this._element.setConfig(config); | ||
this._elementConfig = config; | ||
fireEvent(this, "card-updated"); | ||
} | ||
|
||
private _loadElement(config: LovelaceCardConfig) { | ||
this._element = createCardElement(config); | ||
this._elementConfig = config; | ||
if (this.hass) { | ||
this._element.hass = this.hass; | ||
} | ||
|
@@ -135,15 +144,14 @@ export class HuiCard extends ReactiveElement { | |
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 (changedProps.has("config")) { | ||
const elementConfig = this._elementConfig; | ||
if (this.config !== elementConfig && this.config) { | ||
const typeChanged = this.config?.type !== elementConfig?.type; | ||
if (typeChanged) { | ||
this._loadElement(this.config); | ||
} else { | ||
this._element?.setConfig(this.config); | ||
fireEvent(this, "card-updated"); | ||
this._updateElement(this.config); | ||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid non-null assertions.
Non-null assertions can lead to runtime errors. Use optional chaining (
?.
) or other checks instead.Committable suggestion
Tools
Biome