mirror of
https://github.com/hibiken/asynqmon.git
synced 2025-01-19 03:05:53 +08:00
Minimize the number of writes to local-storage
This commit is contained in:
parent
3c064e0eaf
commit
3547d27214
@ -6,9 +6,17 @@ import App from "./App";
|
||||
import store from "./store";
|
||||
import * as serviceWorker from "./serviceWorker";
|
||||
import { saveState } from "./localStorage";
|
||||
import { SettingsState } from "./reducers/settingsReducer";
|
||||
|
||||
let currentSettings: SettingsState | undefined = undefined;
|
||||
store.subscribe(() => {
|
||||
saveState(store.getState());
|
||||
const prevSettings = currentSettings;
|
||||
currentSettings = store.getState().settings;
|
||||
|
||||
// Write to local-storage only when settings have changed.
|
||||
if (prevSettings !== currentSettings) {
|
||||
saveState(store.getState());
|
||||
}
|
||||
});
|
||||
|
||||
ReactDOM.render(
|
||||
|
@ -9,7 +9,8 @@ export enum ThemePreference {
|
||||
Always,
|
||||
Never,
|
||||
}
|
||||
interface SettingsState {
|
||||
|
||||
export interface SettingsState {
|
||||
pollInterval: number;
|
||||
themePreference: ThemePreference;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user