Skip to content

Commit

Permalink
fix: Clone config in editor. Fixes #233
Browse files Browse the repository at this point in the history
This _should_ fix the issue with frozen objects.
After weighing the options I landed on simply JSON parse/stringify as
the config only holds JSON values and should never be able to hold
cyclic values.
If this turns out to not be correct in the future the logic should be
replaced with a library that does proper deep clone
  • Loading branch information
nervetattoo committed May 21, 2021
1 parent 50cf021 commit 9c27446
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ const stub = {
},
}

const cloneDeep = (obj) => JSON.parse(JSON.stringify(obj))

export default class SimpleThermostatEditor extends LitElement {
config: CardConfig
hass: HASS
Expand Down Expand Up @@ -235,7 +237,7 @@ export default class SimpleThermostatEditor extends LitElement {
return
}
const { target } = ev
const copy = { ...this.config }
const copy = cloneDeep(this.config)
if (target.configValue) {
if (target.value === '') {
delete copy[target.configValue]
Expand Down

0 comments on commit 9c27446

Please sign in to comment.