import createHistory from 'history/lib/createBrowserHistory';
import { compose, createStore, applyMiddleware } from 'redux';
import { apiMiddleware } from 'redux-api-middleware';
import loggerMiddleware from 'redux-logger';
import { reduxReactRouter } from 'redux-react-router';

import routes from 'app/routes';
import rootReducer from 'reducers/index';

let finalCreateStore;

if (__DEVTOOLS__) {
  const { devTools, persistState } = require('redux-devtools');
  finalCreateStore = compose(
    applyMiddleware(apiMiddleware),
    reduxReactRouter({ routes, createHistory }),
    applyMiddleware(loggerMiddleware),
    devTools(),
    persistState(window.location.href.match(/[?&]debug_session=([^&]+)\b/))
  )(createStore);
} else {
  finalCreateStore = compose(
    applyMiddleware(apiMiddleware),
    reduxReactRouter({ routes, createHistory })
  )(createStore);
}

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

  if (module.hot) {
    // Enable Webpack hot module replacement for reducers
    module.hot.accept('reducers', () => {
      const nextRootReducer = require('reducers/index');
      store.replaceReducer(nextRootReducer);
    });
  }

  return store;
}

import createHistory from 'history/lib/createHashHistory';
import { compose, createStore, applyMiddleware } from 'redux';
import { apiMiddleware } from 'redux-api-middleware';
import loggerMiddleware from 'redux-logger';
import { reduxReactRouter } from 'redux-react-router';

import routes from 'app/routes';
import rootReducer from 'reducers/index';

let finalCreateStore;

if (__DEVTOOLS__) {
  const { devTools, persistState } = require('redux-devtools');
  finalCreateStore = compose(
    applyMiddleware(apiMiddleware),
    reduxReactRouter({ routes, createHistory }),
    applyMiddleware(loggerMiddleware),
    devTools(),
    persistState(window.location.href.match(/[?&]debug_session=([^&]+)\b/))
  )(createStore);
} else {
  finalCreateStore = compose(
    applyMiddleware(apiMiddleware),
    reduxReactRouter({ routes, createHistory })
  )(createStore);
}

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

  if (module.hot) {
    // Enable Webpack hot module replacement for reducers
    module.hot.accept('reducers', () => {
      const nextRootReducer = require('reducers/index');
      store.replaceReducer(nextRootReducer);
    });
  }

  return store;
}

Use hash history in routing
Use hash history in routing

Makes routing use hash history instead of HTML5 history
to better work in staging environment.
Refs #34.
