comments
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* @fileOverview
|
||||
* @fileOverview Define API of the server-client communication
|
||||
*/
|
||||
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'
|
||||
import { Connection } from '../connection'
|
||||
|
||||
@@ -28,6 +28,7 @@ interface ProgressState {
|
||||
|
||||
const initialProgressState: ProgressState = loadState() ?? { games: {} }
|
||||
|
||||
// TODO: There was some weird unreproducible bug with removing `as LevelProgressState` here...
|
||||
const initalLevelProgressState: LevelProgressState = {code: "", completed: false, selections: []}
|
||||
|
||||
/** Add an empty skeleton with progress for the current level */
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
/**
|
||||
* @fileOverview configure the store and save the state periodically to the browser storage
|
||||
*/
|
||||
import { configureStore } from '@reduxjs/toolkit';
|
||||
import { debounce } from "debounce";
|
||||
|
||||
@@ -21,10 +24,11 @@ export const store = configureStore({
|
||||
}).concat(apiSlice.middleware),
|
||||
});
|
||||
|
||||
// Save progress in local storage
|
||||
/**
|
||||
* Save progress in local storage once each 800ms.
|
||||
* This is for better performance when multiple changes occur in a short time
|
||||
*/
|
||||
store.subscribe(
|
||||
// we use debounce to save the state once each 800ms
|
||||
// for better performances in case multiple changes occur in a short time
|
||||
debounce(() => {
|
||||
saveState(store.getState()[progressSlice.name]);
|
||||
}, 800)
|
||||
|
||||
Reference in New Issue
Block a user