From a56d5138839ce5c285fb8bae352a199e4f0f5058 Mon Sep 17 00:00:00 2001 From: motzel Date: Tue, 29 Aug 2023 16:34:55 +0200 Subject: [PATCH] feat: update custom stores according to the changed StartStopNotifier interface https://github.com/sveltejs/svelte/pull/6750 --- src/stores/beatleader/stats-history.js | 3 ++- src/stores/config.js | 4 +++- src/stores/localstorage.js | 13 +++++++++---- src/stores/playlists.js | 3 +++ 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/stores/beatleader/stats-history.js b/src/stores/beatleader/stats-history.js index 633033ccb..db7a42b00 100644 --- a/src/stores/beatleader/stats-history.js +++ b/src/stores/beatleader/stats-history.js @@ -12,7 +12,7 @@ export default () => { let votingStatuses = {}; const get = () => votingStatuses; - const {subscribe: subscribeState, set} = writable(votingStatuses); + const {subscribe: subscribeState, set, update} = writable(votingStatuses); const fetchStats = async (playerData, count = 50) => { if (!playerData) return; @@ -88,6 +88,7 @@ export default () => { subscribe, get, set, + update, fetchStats, }; diff --git a/src/stores/config.js b/src/stores/config.js index 76befa7d2..26066246a 100644 --- a/src/stores/config.js +++ b/src/stores/config.js @@ -186,6 +186,8 @@ export default async () => { return newConfig; }; + const update = fn => set(fn(currentConfig)); + const setForKey = async (key, value, persist = true) => { currentConfig[key] = value; @@ -195,7 +197,6 @@ export default async () => { } settingsChanged = !deepEqual(currentConfig, dbConfig); - currentConfig = currentConfig; storeSet(currentConfig); return currentConfig; @@ -260,6 +261,7 @@ export default async () => { configStore = { subscribe, set, + update, get, getLocale, setForKey, diff --git a/src/stores/localstorage.js b/src/stores/localstorage.js index 9417379e6..6ec7c1005 100644 --- a/src/stores/localstorage.js +++ b/src/stores/localstorage.js @@ -3,19 +3,24 @@ import {writable} from 'svelte/store'; export default (key, initial = {}, prefix = 'bl-') => { const lsKey = `${prefix}-${key}`; - const value = JSON.parse(localStorage.getItem(lsKey)) ?? initial; + let value = JSON.parse(localStorage.getItem(lsKey)) ?? initial; const {subscribe, unsubscribe, set: storeSet} = writable(value ?? initial); - const set = value => { - localStorage.setItem(lsKey, JSON.stringify(value)); + const set = newValue => { + localStorage.setItem(lsKey, JSON.stringify(newValue)); - storeSet(value); + value = newValue; + + storeSet(newValue); }; + const update = fn => set(fn(value)); + return { subscribe, unsubscribe, set, + update, }; }; diff --git a/src/stores/playlists.js b/src/stores/playlists.js index c443ea01c..bc22537d8 100644 --- a/src/stores/playlists.js +++ b/src/stores/playlists.js @@ -53,6 +53,8 @@ export default () => { return newConfig; }; + const update = fn => set(fn(playlists)); + const create = async (song = null, inputPlaylist = null) => { const playlist = inputPlaylist ? inputPlaylist @@ -290,6 +292,7 @@ export default () => { subscribe, unsubscribe, set, + update, get, create, select,