"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = configureStore;

var _redux = require("redux");

var _reactRouterRedux = require("react-router-redux");

var _reduxThunk = _interopRequireDefault(require("redux-thunk"));

var _topologicallyCombineReducers = _interopRequireDefault(require("topologically-combine-reducers"));

var actions = _interopRequireWildcard(require("./actions"));

var _shortcuts = _interopRequireDefault(require("./shortcuts"));

var _reducers = _interopRequireWildcard(require("./reducers"));

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

function configureStore(history, initial) {
  const reducer = hydrateable((0, _topologicallyCombineReducers.default)(_extends({
    routing: _reactRouterRedux.routerReducer
  }, _reducers.default), _reducers.dependencies));
  const enhance = global.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || _redux.compose;
  const middlewares = [_reduxThunk.default, (0, _reactRouterRedux.routerMiddleware)(history)];
  /* if (process.env.NODE_ENV !== "production") {
    middlewares.push(require("redux-freeze"));
  }
  */

  const middleware = (0, _redux.applyMiddleware)(...middlewares);
  const shortcuts = (0, _shortcuts.default)();
  const store = (0, _redux.createStore)(reducer, _extends({}, initial, {
    shortcuts
  }), enhance(middleware));
  listen(store, {
    url: "/api"
  });
  shortcuts(store);
  return store;
}

function hydrateable(reducer) {
  return (state, action) => {
    switch (action.type) {
      case "@@APPLY_STATE":
        return reducer(action.payload, action);

      default:
        return reducer(state, action);
    }
  };
}

function listen(store, options) {
  store.dispatch(actions.listen({
    url: options.url
  }));
}
//# sourceMappingURL=store.js.map