save state to localStorage
This commit is contained in:
parent
da4b5b318e
commit
948fe96e0a
@ -25,7 +25,6 @@
|
|||||||
export let rating = 0;
|
export let rating = 0;
|
||||||
export let api = getContext("api");
|
export let api = getContext("api");
|
||||||
|
|
||||||
console.log(api?.dispatch?.setDrive);
|
|
||||||
$: api?.dispatch?.setDrive?.({ rating, advanced });
|
$: api?.dispatch?.setDrive?.({ rating, advanced });
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -1,9 +1,20 @@
|
|||||||
import ship from "./ship";
|
import ship from "./ship";
|
||||||
|
import { browser } from "$app/environment";
|
||||||
|
|
||||||
export type Api = ReturnType<typeof ship.createStore>;
|
export type Api = ReturnType<typeof ship.createStore>;
|
||||||
|
|
||||||
export const createApi = () => {
|
export const createApi = () => {
|
||||||
const api = ship.createStore();
|
const state = browser
|
||||||
console.log(api);
|
? JSON.parse(localStorage.getItem("ship") || "null")
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
const api = ship.createStore(state || undefined);
|
||||||
|
|
||||||
|
if (browser) {
|
||||||
|
api.subscribe(() => {
|
||||||
|
localStorage.setItem("ship", JSON.stringify(api.getState()));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return api;
|
return api;
|
||||||
};
|
};
|
||||||
|
@ -100,11 +100,6 @@ shipDux.addReaction((api) => {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
shipDux.addEffect((api) => (next) => (action) => {
|
|
||||||
console.log(action);
|
|
||||||
next(action);
|
|
||||||
});
|
|
||||||
|
|
||||||
shipDux.addReaction((api) =>
|
shipDux.addReaction((api) =>
|
||||||
createSelector(
|
createSelector(
|
||||||
api.selectors.getShipMass,
|
api.selectors.getShipMass,
|
||||||
|
1
src/routes/+layout.js
Normal file
1
src/routes/+layout.js
Normal file
@ -0,0 +1 @@
|
|||||||
|
export const prerender = true;
|
@ -8,7 +8,7 @@
|
|||||||
export let api = getContext("api");
|
export let api = getContext("api");
|
||||||
|
|
||||||
let ship = {};
|
let ship = {};
|
||||||
api.subscribe(() => {
|
api?.subscribe(() => {
|
||||||
ship = api.getState();
|
ship = api.getState();
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
Reference in New Issue
Block a user