Browse Source

fix middleware to save countervalues

master
Gaëtan Renaudeau 7 years ago
parent
commit
addbd0ee43
  1. 26
      src/middlewares/db.js

26
src/middlewares/db.js

@ -7,17 +7,19 @@ import { settingsExportSelector } from 'reducers/settings'
import CounterValues from 'helpers/countervalues'
export default store => next => action => {
if (!action.type.startsWith('DB:')) {
return next(action)
if (action.type.startsWith('DB:')) {
const [, type] = action.type.split(':')
store.dispatch({ type, payload: action.payload })
const state = store.getState()
db.set('settings', settingsExportSelector(state))
db.set('accounts', getAccounts(state))
} else {
const oldState = store.getState()
const res = next(action)
const newState = store.getState()
if (oldState.countervalues !== newState.countervalues) {
db.set('countervalues', CounterValues.exportSelector(newState))
}
return res
}
const { dispatch, getState } = store
const [, type] = action.type.split(':')
dispatch({ type, payload: action.payload })
const state = getState()
db.set('settings', settingsExportSelector(state))
db.set('accounts', getAccounts(state))
db.set('countervalues', CounterValues.exportSelector(state))
}

Loading…
Cancel
Save