import { createStore, applyMiddleware, compose } from 'redux';
import persistState from 'redux-localstorage';
import { apiMiddleware } from 'redux-api-middleware';
import thunk from 'redux-thunk';
import apiMiddlewareHook from 'reducers/middlewares/apiMiddlewareHook';
import camelizeState from 'reducers/middlewares/camelizeState';
import { hashHistory } from 'react-router';
import { syncHistory } from 'react-router-redux';
import rootReducer from '../reducers';

const router = syncHistory(hashHistory);

const middlewares = [
  thunk, router, apiMiddlewareHook, apiMiddleware, camelizeState
];

if (process.env.NODE_ENV === 'developement') {
  const createLogger = require('redux-logger');
  const logger = createLogger();
  middlewares.push(logger);
}

const enhancer = compose(
  applyMiddleware(...middlewares),
  persistState(['auth'], { key: `douban_sauce_${process.env.NODE_ENV || 'development'}.auth` })
);

export default function configureStore(initialState) {
  const store = createStore(rootReducer, initialState, enhancer);

  if (process.env.NODE_ENV === 'development') {
    router.listenForReplays(store);

    if (module.hot) {
      module.hot.accept('../reducers', () =>
        store.replaceReducer(require('../reducers'))
      );
    }
  }

  return store;
}

import { createStore, applyMiddleware, compose } from 'redux';
import persistState from 'redux-localstorage';
import { apiMiddleware } from 'redux-api-middleware';
import thunk from 'redux-thunk';
import apiMiddlewareHook from 'reducers/middlewares/apiMiddlewareHook';
import camelizeState from 'reducers/middlewares/camelizeState';
import { hashHistory } from 'react-router';
import { syncHistory } from 'react-router-redux';
import rootReducer from '../reducers';

const router = syncHistory(hashHistory);

const middlewares = [
  thunk, router, apiMiddlewareHook, apiMiddleware, camelizeState
];

if (process.env.NODE_ENV === 'development') {
  const createLogger = require('redux-logger');
  const logger = createLogger();
  middlewares.push(logger);
}

const enhancer = compose(
  applyMiddleware(...middlewares),
  persistState(['auth'], { key: `douban_sauce_${process.env.NODE_ENV || 'development'}.auth` })
);

export default function configureStore(initialState) {
  const store = createStore(rootReducer, initialState, enhancer);

  if (process.env.NODE_ENV === 'development') {
    router.listenForReplays(store);

    if (module.hot) {
      module.hot.accept('../reducers', () =>
        store.replaceReducer(require('../reducers'))
      );
    }
  }

  return store;
}

fix log disappear bug