This commit is contained in:
Jon Eugster
2023-07-05 18:05:53 +02:00
parent 4039fa9467
commit 042bf37f1d
3 changed files with 9 additions and 4 deletions
+7 -3
View File
@@ -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)