init the store the right way

docks66-json-schema
Yanick Champoux 2023-05-04 16:45:40 -04:00
parent 43addc4072
commit c728f8c09d
2 changed files with 12 additions and 8 deletions

View File

@ -5,17 +5,17 @@ import { writable } from "svelte/store";
export type Api = ReturnType<typeof ship.createStore>;
export const createApi = () => {
const state = browser
? JSON.parse(localStorage.getItem("ship") || "null")
: undefined;
const options: Partial<{ preloadedState: object }> = {};
const api = ship.createStore({
preloadedState: state,
});
const preloadedState = browser && localStorage.getItem("ship");
if (preloadedState) options.preloadedState = JSON.parse(preloadedState);
api.dispatch.restore(state);
const api = ship.createStore(options);
const svelteStore = writable(state);
const svelteStore = writable();
if (preloadedState) {
svelteStore.set(JSON.parse(preloadedState));
}
if (browser) {
api.subscribe(() => {

View File

@ -1,8 +1,12 @@
import preprocess from "svelte-preprocess";
import adapter from "@sveltejs/adapter-static";
/** @type {import('@sveltejs/kit').Config} */
const config = {
preprocess: preprocess(),
kit: {
adapter: adapter({}),
},
};
export default config;