Skip to content

Commit a56d513

Browse files
committed
feat: update custom stores according to the changed StartStopNotifier interface
sveltejs/svelte#6750
1 parent ac5d7e2 commit a56d513

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed

src/stores/beatleader/stats-history.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default () => {
1212
let votingStatuses = {};
1313

1414
const get = () => votingStatuses;
15-
const {subscribe: subscribeState, set} = writable(votingStatuses);
15+
const {subscribe: subscribeState, set, update} = writable(votingStatuses);
1616

1717
const fetchStats = async (playerData, count = 50) => {
1818
if (!playerData) return;
@@ -88,6 +88,7 @@ export default () => {
8888
subscribe,
8989
get,
9090
set,
91+
update,
9192
fetchStats,
9293
};
9394

src/stores/config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ export default async () => {
186186
return newConfig;
187187
};
188188

189+
const update = fn => set(fn(currentConfig));
190+
189191
const setForKey = async (key, value, persist = true) => {
190192
currentConfig[key] = value;
191193

@@ -195,7 +197,6 @@ export default async () => {
195197
}
196198

197199
settingsChanged = !deepEqual(currentConfig, dbConfig);
198-
currentConfig = currentConfig;
199200
storeSet(currentConfig);
200201

201202
return currentConfig;
@@ -260,6 +261,7 @@ export default async () => {
260261
configStore = {
261262
subscribe,
262263
set,
264+
update,
263265
get,
264266
getLocale,
265267
setForKey,

src/stores/localstorage.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,24 @@ import {writable} from 'svelte/store';
33
export default (key, initial = {}, prefix = 'bl-') => {
44
const lsKey = `${prefix}-${key}`;
55

6-
const value = JSON.parse(localStorage.getItem(lsKey)) ?? initial;
6+
let value = JSON.parse(localStorage.getItem(lsKey)) ?? initial;
77

88
const {subscribe, unsubscribe, set: storeSet} = writable(value ?? initial);
99

10-
const set = value => {
11-
localStorage.setItem(lsKey, JSON.stringify(value));
10+
const set = newValue => {
11+
localStorage.setItem(lsKey, JSON.stringify(newValue));
1212

13-
storeSet(value);
13+
value = newValue;
14+
15+
storeSet(newValue);
1416
};
1517

18+
const update = fn => set(fn(value));
19+
1620
return {
1721
subscribe,
1822
unsubscribe,
1923
set,
24+
update,
2025
};
2126
};

src/stores/playlists.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ export default () => {
5353
return newConfig;
5454
};
5555

56+
const update = fn => set(fn(playlists));
57+
5658
const create = async (song = null, inputPlaylist = null) => {
5759
const playlist = inputPlaylist
5860
? inputPlaylist
@@ -290,6 +292,7 @@ export default () => {
290292
subscribe,
291293
unsubscribe,
292294
set,
295+
update,
293296
get,
294297
create,
295298
select,

0 commit comments

Comments
 (0)