diff --git a/client/src/state/api.ts b/client/src/state/api.ts index 84d083f..022bf0e 100644 --- a/client/src/state/api.ts +++ b/client/src/state/api.ts @@ -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' diff --git a/client/src/state/progress.ts b/client/src/state/progress.ts index 137c571..b82fd5b 100644 --- a/client/src/state/progress.ts +++ b/client/src/state/progress.ts @@ -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 */ diff --git a/client/src/state/store.ts b/client/src/state/store.ts index 94746ce..4079ebd 100644 --- a/client/src/state/store.ts +++ b/client/src/state/store.ts @@ -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)