From 9631927a8cbbc739f1e1d0d574c61e19803ee0dc Mon Sep 17 00:00:00 2001 From: fragosti Date: Fri, 25 May 2018 12:02:45 -0700 Subject: Add localstorage helper --- packages/website/ts/local_storage/state_storage.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 packages/website/ts/local_storage/state_storage.ts (limited to 'packages/website/ts') diff --git a/packages/website/ts/local_storage/state_storage.ts b/packages/website/ts/local_storage/state_storage.ts new file mode 100644 index 000000000..517784b5b --- /dev/null +++ b/packages/website/ts/local_storage/state_storage.ts @@ -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): void { + localStorage.setObject(STORAGE_NAME, partialState); + }, + getPersistedState(): Partial { + return localStorage.getObject(STORAGE_NAME); + }, + getPersistedDefaultState(): State { + return { ...INITIAL_STATE, ...stateStorage.getPersistedState() }; + }, +}; -- cgit v1.2.3