Add localstorage helper
This commit is contained in:
16
packages/website/ts/local_storage/state_storage.ts
Normal file
16
packages/website/ts/local_storage/state_storage.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { localStorage } from 'ts/local_storage/local_storage';
|
||||
import { INITIAL_STATE, State } from 'ts/redux/reducer';
|
||||
|
||||
const STORAGE_NAME = 'persistedState';
|
||||
|
||||
export const stateStorage = {
|
||||
saveState(partialState: Partial<State>): void {
|
||||
localStorage.setObject(STORAGE_NAME, partialState);
|
||||
},
|
||||
getPersistedState(): Partial<State> {
|
||||
return localStorage.getObject(STORAGE_NAME);
|
||||
},
|
||||
getPersistedDefaultState(): State {
|
||||
return { ...INITIAL_STATE, ...stateStorage.getPersistedState() };
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user