this is hight order reducer that has only 2 possible actions
INIT_STORE: action that will be dispached right after cached data will be retrived from whatever storage and reinitilize react app with cached dataRESET_STORE: action that can be used on logout to clear whole redux store
persistReducer(whiteList)
whiteList is array of redux store keys should not be deleted on RESET_STORE store action. For example, u can add site configs to whitelist or, in case, there is react-router connected to redux, it also should be whitelisted. It is better to store this config in .env file.
import { persistReducer } from 'ds-cache'
composeReducers(
{},
combineReducers({
form,
nav,
}),
persistReducer(JSON.parse(process.env.CACHE_STATE_PERSIST_KEYS)),
)reset action with type RESET_STORE mostly will be used on logout
cacheMiddleware is redux middleware that will cache your redux store to whatever storage
by default nothing will be stored. You should add some keys that are needed to be cached. In case this param is empty, probably, you should not use this module.
Storage has same api as AsyncStorage or Window.localStorage
class OwnStorage {
constructor(){
this.store = new Map()
}
getItem(key){
return this.store.get[key]
}
setItem(key, value){
this.store.set(key, value)
}
}