Skip to content

Commit

Permalink
feat: update custom stores according to the changed StartStopNotifier…
Browse files Browse the repository at this point in the history
… interface

sveltejs/svelte#6750
  • Loading branch information
motzel committed Aug 29, 2023
1 parent ac5d7e2 commit a56d513
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/stores/beatleader/stats-history.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -88,6 +88,7 @@ export default () => {
subscribe,
get,
set,
update,
fetchStats,
};

Expand Down
4 changes: 3 additions & 1 deletion src/stores/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

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

settingsChanged = !deepEqual(currentConfig, dbConfig);
currentConfig = currentConfig;
storeSet(currentConfig);

return currentConfig;
Expand Down Expand Up @@ -260,6 +261,7 @@ export default async () => {
configStore = {
subscribe,
set,
update,
get,
getLocale,
setForKey,
Expand Down
13 changes: 9 additions & 4 deletions src/stores/localstorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
};
3 changes: 3 additions & 0 deletions src/stores/playlists.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -290,6 +292,7 @@ export default () => {
subscribe,
unsubscribe,
set,
update,
get,
create,
select,
Expand Down

0 comments on commit a56d513

Please sign in to comment.