mirror of
https://github.com/hibiken/asynqmon.git
synced 2025-01-19 11:15: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 store from "./store";
|
||||||
import * as serviceWorker from "./serviceWorker";
|
import * as serviceWorker from "./serviceWorker";
|
||||||
import { saveState } from "./localStorage";
|
import { saveState } from "./localStorage";
|
||||||
|
import { SettingsState } from "./reducers/settingsReducer";
|
||||||
|
|
||||||
|
let currentSettings: SettingsState | undefined = undefined;
|
||||||
store.subscribe(() => {
|
store.subscribe(() => {
|
||||||
|
const prevSettings = currentSettings;
|
||||||
|
currentSettings = store.getState().settings;
|
||||||
|
|
||||||
|
// Write to local-storage only when settings have changed.
|
||||||
|
if (prevSettings !== currentSettings) {
|
||||||
saveState(store.getState());
|
saveState(store.getState());
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
ReactDOM.render(
|
ReactDOM.render(
|
||||||
|
@ -9,7 +9,8 @@ export enum ThemePreference {
|
|||||||
Always,
|
Always,
|
||||||
Never,
|
Never,
|
||||||
}
|
}
|
||||||
interface SettingsState {
|
|
||||||
|
export interface SettingsState {
|
||||||
pollInterval: number;
|
pollInterval: number;
|
||||||
themePreference: ThemePreference;
|
themePreference: ThemePreference;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user