accounts-frontend/packages/app/storeFactory.ts
ErickSkrauch 82abe0a746
Extract general popups markup to its own component
Split popups controllers into separate components
Implemented storybooks for all project's popups
2020-07-06 19:29:56 +03:00

35 lines
1.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { createStore, applyMiddleware, compose, StoreEnhancer } from 'redux';
// midleware, который позволяет возвращать из экшенов функции
// это полезно для работы с асинхронными действиями,
// а также дает возможность проверить какие-либо условия перед запуском экшена
// или даже вообще его не запускать в зависимости от условий
import thunk from 'redux-thunk';
import persistState from 'redux-localstorage';
import reducers, { Store } from 'app/reducers';
export default function storeFactory(preloadedState = {}): Store {
const middlewares = applyMiddleware(thunk);
const persistStateEnhancer = persistState(['accounts', 'user'], {
key: 'redux-storage',
});
let enhancer: StoreEnhancer;
if (process.env.NODE_ENV === 'production') {
enhancer = compose(middlewares, persistStateEnhancer);
} else {
const composeEnhancers = (window as any).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
enhancer = composeEnhancers(middlewares, persistStateEnhancer);
}
const store = createStore(reducers, preloadedState, enhancer) as Store;
// Hot reload reducers
if (module.hot && typeof module.hot.accept === 'function') {
module.hot.accept('app/reducers', () => store.replaceReducer(require('app/reducers').default));
}
return store;
}