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 type Api = ReturnType<typeof ship.createStore>;
|
||||||
|
|
||||||
export const createApi = () => {
|
export const createApi = () => {
|
||||||
const state = browser
|
const options: Partial<{ preloadedState: object }> = {};
|
||||||
? JSON.parse(localStorage.getItem("ship") || "null")
|
|
||||||
: undefined;
|
|
||||||
|
|
||||||
const api = ship.createStore({
|
const preloadedState = browser && localStorage.getItem("ship");
|
||||||
preloadedState: state,
|
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) {
|
if (browser) {
|
||||||
api.subscribe(() => {
|
api.subscribe(() => {
|
||||||
|
@ -1,8 +1,12 @@
|
|||||||
import preprocess from "svelte-preprocess";
|
import preprocess from "svelte-preprocess";
|
||||||
|
import adapter from "@sveltejs/adapter-static";
|
||||||
|
|
||||||
/** @type {import('@sveltejs/kit').Config} */
|
/** @type {import('@sveltejs/kit').Config} */
|
||||||
const config = {
|
const config = {
|
||||||
preprocess: preprocess(),
|
preprocess: preprocess(),
|
||||||
|
kit: {
|
||||||
|
adapter: adapter({}),
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export default config;
|
export default config;
|
||||||
|
Loading…
Reference in New Issue
Block a user