Module for store state saving
$ npm install --save redux-local-save
import { createStore, applyMiddleware } from 'redux'
import createLocalSaveMiddleware, { loadStorage } from 'redux-local-save'
//Create middleware for installation.
const localSaveMiddleware = createLocalSaveMiddleware({
//We specify actions which will start saving
saveActions: [
TEST_SAVE,
//Debounce: each call defers saving to 300ms
{ type: TEST_SAVE_WITH_DEBOUNCE, debounce: 300 },
//Throttle: call no more than 200ms
{ type: TEST_SAVE_WITH_THROTTLE, throttle: 200 }
]
})
const store = createStore(
reducer,
//Load the saved state
loadStorage(),
applyMiddleware(localSaveMiddleware)
)
//userStore.js
...
const localSaveMiddleware = createLocalSaveMiddleware({
//We specify actions which will start saving
saveName: 'userStore'
})
const store = createStore(
reducer,
loadStorage('userStore'),
applyMiddleware(localSaveMiddleware)
)
...
//animalStore.js
...
const localSaveMiddleware = createLocalSaveMiddleware({
//We specify actions which will start saving
saveName: 'animalStore'
})
const store = createStore(
reducer,
loadStorage('animalStore'),
applyMiddleware(localSaveMiddleware)
)
...
const localSaveMiddleware = createLocalSaveMiddleware({
//there are two types of "saveAction"
saveActions: [
//1. DUMB
SEND_CURRENT_WORD,
//2. SMART (for example, added a parameter that defer saving (for 200 ms) after each action)
{type: SEND_PREVIOUS_WORD, debounce: 200},
]
})
MIT © jeckyhit