save state to localStorage
This commit is contained in:
parent
da4b5b318e
commit
948fe96e0a
@ -25,7 +25,6 @@
|
||||
export let rating = 0;
|
||||
export let api = getContext("api");
|
||||
|
||||
console.log(api?.dispatch?.setDrive);
|
||||
$: api?.dispatch?.setDrive?.({ rating, advanced });
|
||||
</script>
|
||||
|
||||
|
@ -1,9 +1,20 @@
|
||||
import ship from "./ship";
|
||||
import { browser } from "$app/environment";
|
||||
|
||||
export type Api = ReturnType<typeof ship.createStore>;
|
||||
|
||||
export const createApi = () => {
|
||||
const api = ship.createStore();
|
||||
console.log(api);
|
||||
const state = browser
|
||||
? 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;
|
||||
};
|
||||
|
@ -100,11 +100,6 @@ shipDux.addReaction((api) => {
|
||||
};
|
||||
});
|
||||
|
||||
shipDux.addEffect((api) => (next) => (action) => {
|
||||
console.log(action);
|
||||
next(action);
|
||||
});
|
||||
|
||||
shipDux.addReaction((api) =>
|
||||
createSelector(
|
||||
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");
|
||||
|
||||
let ship = {};
|
||||
api.subscribe(() => {
|
||||
api?.subscribe(() => {
|
||||
ship = api.getState();
|
||||
});
|
||||
</script>
|
||||
|
Loading…
Reference in New Issue
Block a user