From 8601da786cbef65c440c29b2c3eb322f57219c27 Mon Sep 17 00:00:00 2001 From: SleepWalker Date: Mon, 31 Oct 2016 08:51:38 +0200 Subject: [PATCH] #48: add accounts reducer and set up localStorage persistance --- package.json | 1 + src/reducers.js | 2 ++ src/storeFactory.js | 8 ++++++-- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 0f4c716..c7bb99d 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "react-router": "^2.0.0", "react-router-redux": "^3.0.0", "redux": "^3.0.4", + "redux-localstorage": "^0.4.1", "redux-thunk": "^2.0.0", "webfontloader": "^1.6.26", "whatwg-fetch": "^1.0.0" diff --git a/src/reducers.js b/src/reducers.js index 90bab89..7161456 100644 --- a/src/reducers.js +++ b/src/reducers.js @@ -4,6 +4,7 @@ import { routeReducer } from 'react-router-redux'; import auth from 'components/auth/reducer'; import user from 'components/user/reducer'; +import accounts from 'components/accounts/reducer'; import i18n from 'components/i18n/reducer'; import popup from 'components/ui/popup/reducer'; import bsod from 'components/ui/bsod/reducer'; @@ -12,6 +13,7 @@ export default combineReducers({ bsod, auth, user, + accounts, i18n, popup, routing: routeReducer diff --git a/src/storeFactory.js b/src/storeFactory.js index 0febcd6..90b1dd6 100644 --- a/src/storeFactory.js +++ b/src/storeFactory.js @@ -4,6 +4,7 @@ import { createStore, applyMiddleware, compose } from 'redux'; // а также дает возможность проверить какие-либо условия перед запуском экшена // или даже вообще его не запускать в зависимости от условий import thunk from 'redux-thunk'; +import persistState from 'redux-localstorage'; import { syncHistory } from 'react-router-redux'; import { browserHistory } from 'react-router'; @@ -15,14 +16,17 @@ export default function storeFactory() { reduxRouterMiddleware, thunk ); + const persistStateEnhancer = persistState([ + 'accounts' + ], {key: 'redux-storage'}); /* global process: false */ let enhancer; if (process.env.NODE_ENV === 'production') { - enhancer = compose(middlewares); + enhancer = compose(middlewares, persistStateEnhancer); } else { const DevTools = require('containers/DevTools').default; - enhancer = compose(middlewares, DevTools.instrument()); + enhancer = compose(middlewares, persistStateEnhancer, DevTools.instrument()); } const store = createStore(reducers, {}, enhancer);