Skip to content

Commit

Permalink
Treat the _config as immutable.
Browse files Browse the repository at this point in the history
Might fix an issue with the template editor reported by a user.
  • Loading branch information
j9brown committed Sep 23, 2024
1 parent ef3228d commit 32db5b2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "decluttering-card",
"version": "1.0.3",
"version": "1.0.4",
"description": "Decluttering Card for Lovelace",
"main": "dist/decluttering-card.js",
"scripts": {
Expand Down
24 changes: 11 additions & 13 deletions src/decluttering-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -607,32 +607,30 @@ class DeclutteringTemplateEditor extends LitElement implements LovelaceCardEdito
private _valueChanged(ev: CustomEvent): void {
if (!this._config) return;
const data = ev.detail.value;

this._config.template = data.template;
DeclutteringTemplateEditor.stubMember(data.thingType === 'card', this._config, 'card', {
const config = { ...this._config, template: data.template, default: data.default };
DeclutteringTemplateEditor.stubMember(data.thingType === 'card', config, 'card', {
type: 'entity',
entity: 'sun.sun',
});
DeclutteringTemplateEditor.stubMember(data.thingType === 'row', this._config, 'row', {
DeclutteringTemplateEditor.stubMember(data.thingType === 'row', config, 'row', {
entity: 'sun.sun',
});
DeclutteringTemplateEditor.stubMember(data.thingType === 'element', this._config, 'element', {
DeclutteringTemplateEditor.stubMember(data.thingType === 'element', config, 'element', {
type: 'icon',
icon: 'mdi:weather-sunny',
style: {
color: 'yellow',
},
});
this._config.default = data.default;
this._fireConfigChanged();
this._fireConfigChanged(config);
}

private _cardChanged(ev: CustomEvent): void {
ev.stopPropagation();
if (!this._config) return;

this._config.card = ev.detail.config;
this._fireConfigChanged();
const config = { ...this._config, card: ev.detail.config };
this._fireConfigChanged(config);
}

private _cardPicked(ev: CustomEvent): void {
Expand All @@ -644,12 +642,12 @@ class DeclutteringTemplateEditor extends LitElement implements LovelaceCardEdito
ev.stopPropagation();
if (!this._config) return;

this._config.row = ev.detail.config;
this._fireConfigChanged();
const config = { ...this._config, row: ev.detail.config };
this._fireConfigChanged(config);
}

private _fireConfigChanged(): void {
fireEvent(this, 'config-changed', { config: this._config });
private _fireConfigChanged(config: DeclutteringTemplateConfig): void {
fireEvent(this, 'config-changed', { config });
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down

0 comments on commit 32db5b2

Please sign in to comment.