init the store the right way
This commit is contained in:
parent
43addc4072
commit
c728f8c09d
@ -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(() => {
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user