24 lines
568 B
JavaScript
24 lines
568 B
JavaScript
import { writable } from 'svelte/store';
|
|
import { browser } from '$app/environment';
|
|
|
|
export const welcome = writable(fromLocalStorage('welcome', '0'));
|
|
toLocalStorage(welcome, 'welcome');
|
|
|
|
function fromLocalStorage(storageKey, fallback) {
|
|
if (browser) {
|
|
const storedValue = localStorage.getItem(storageKey);
|
|
if (storedValue !== 'undefined') {
|
|
return storedValue;
|
|
}
|
|
}
|
|
return fallback;
|
|
}
|
|
|
|
function toLocalStorage(store, storageKey) {
|
|
if (browser) {
|
|
store.subscribe((value) => {
|
|
localStorage.setItem(storageKey, value);
|
|
});
|
|
}
|
|
}
|