Fix smaller problems in storage state

This commit is contained in:
Talia 2023-09-20 11:23:33 +02:00
parent 8c01bd83ca
commit 2c2adba2b6

View file

@ -93,7 +93,7 @@ export class StoredState extends State {
constructor(init, options={}) { constructor(init, options={}) {
super({}, options) super({}, options)
this.#storage = options.storage ?? localStorage this.#storage = options.storage ?? localStorage ?? new MapStorage()
this.#valueKey = options.key ?? 'value' this.#valueKey = options.key ?? 'value'
// Initialise storage from defaults // Initialise storage from defaults
@ -114,7 +114,7 @@ export class StoredState extends State {
addEventListener("storage", event => { addEventListener("storage", event => {
let prop = event.key let prop = event.key
if (prop === this.#valueKey) prop = 'value' if (prop === this.#valueKey) prop = 'value'
this.emit(prop, event.newValue) this.emit(prop, JSON.parse(event.newValue))
}) })
} }