2018-04-06 14:51:52 +01:00
|
|
|
import {
|
|
|
|
createStore as reduxCreateStore,
|
|
|
|
combineReducers,
|
|
|
|
applyMiddleware
|
|
|
|
} from 'redux';
|
|
|
|
import { combineEpics, createEpicMiddleware } from 'redux-observable';
|
|
|
|
import { routerReducer as router, routerMiddleware } from 'react-router-redux';
|
|
|
|
|
2018-04-13 15:33:03 +01:00
|
|
|
import { reducer as formReducer } from 'redux-form';
|
|
|
|
|
2018-05-18 19:07:32 +01:00
|
|
|
import analyticsEpic from '../analytics/analytics-epic';
|
2018-04-12 16:06:40 +01:00
|
|
|
import { reducer as app, epics as appEpics } from './app';
|
|
|
|
import {
|
|
|
|
reducer as challenge,
|
|
|
|
epics as challengeEpics
|
|
|
|
} from '../templates/Challenges/redux';
|
2018-04-06 14:51:52 +01:00
|
|
|
import { reducer as map } from '../components/Map/redux';
|
2018-05-24 19:45:38 +01:00
|
|
|
import servicesCreator from './createServices';
|
|
|
|
import { _csrf } from './cookieVaules';
|
|
|
|
|
|
|
|
const serviceOptions = {
|
|
|
|
context: _csrf ? { _csrf } : {},
|
|
|
|
xhrPath: '/external/services',
|
|
|
|
xhrTimeout: 15000
|
|
|
|
};
|
2018-04-06 14:51:52 +01:00
|
|
|
|
|
|
|
const rootReducer = combineReducers({
|
2018-04-11 14:46:46 +01:00
|
|
|
app,
|
2018-04-06 14:51:52 +01:00
|
|
|
challenge,
|
2018-04-13 15:33:03 +01:00
|
|
|
form: formReducer,
|
2018-04-06 14:51:52 +01:00
|
|
|
map,
|
|
|
|
router
|
|
|
|
});
|
|
|
|
|
2018-05-18 19:07:32 +01:00
|
|
|
const rootEpic = combineEpics(analyticsEpic, ...appEpics, ...challengeEpics);
|
2018-04-11 14:46:46 +01:00
|
|
|
|
2018-04-06 14:51:52 +01:00
|
|
|
const epicMiddleware = createEpicMiddleware(rootEpic, {
|
|
|
|
dependencies: {
|
|
|
|
window: typeof window !== 'undefined' ? window : {},
|
2018-05-24 19:45:38 +01:00
|
|
|
document: typeof window !== 'undefined' ? document : {},
|
|
|
|
services: servicesCreator(serviceOptions)
|
2018-04-06 14:51:52 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export const createStore = history =>
|
|
|
|
reduxCreateStore(
|
|
|
|
rootReducer,
|
|
|
|
applyMiddleware(epicMiddleware, routerMiddleware(history))
|
|
|
|
);
|