All files / src/redux store.js

100% Statements 13/13
100% Branches 4/4
100% Functions 3/3
100% Lines 12/12
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54                            2x 3x 3x 2x     2x   2x       2x 13x                                     2x   2x 1x     2x  
import { createStore, combineReducers, applyMiddleware, compose } from "redux";
import { routerReducer, routerMiddleware } from "react-router-redux";
import { history } from "../router/Router";
import { createLogger } from "redux-logger";
import {
  loginReducer,
  searchReducer,
  recommendationsReducer
} from "./reducers";
import thunkMiddleware from "redux-thunk";
import { middleware, initializeState } from "./middleware";
//import initialState from './state2'
//import initialState from "./results/recomendations";
 
export const getStateFromCache = () => {
  let cachedState = localStorage["redux-store"];
  if (cachedState) return JSON.parse(cachedState);
  return {};
};
 
const initialState = getStateFromCache();
 
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
 
// Add the reducer to your store on the `router` key
// Also apply our middleware for navigating
export const storeFactory = initialState =>
  createStore(
    combineReducers({
      //...reducers,
      search: searchReducer,
      recommendations: recommendationsReducer,
      user: loginReducer,
      router: routerReducer
    }),
    initializeState(initialState),
    composeEnhancers(
      applyMiddleware(
        thunkMiddleware,
        middleware,
        routerMiddleware(history),
        createLogger()
      )
    )
  );
 
const theStore = storeFactory(initialState);
 
theStore.subscribe(() => {
  localStorage["redux-store"] = JSON.stringify(store.getState());
});
 
export const store = theStore;