2016-03-22 04:27:44 +01:00
|
|
|
import $ from 'jQuery';
|
2016-03-16 01:30:39 +01:00
|
|
|
import { combineReducers, createStore, applyMiddleware } from 'redux';
|
|
|
|
import thunkMiddleware from 'redux-thunk';
|
|
|
|
import createLogger from 'redux-logger';
|
|
|
|
import reducerRegister from 'reducer-register';
|
|
|
|
|
2016-03-26 06:41:24 +01:00
|
|
|
import * as configActions from 'state/config/actions';
|
|
|
|
import ConfigReducer from 'state/config/reducer';
|
|
|
|
import SchemaReducer from 'state/schema/reducer';
|
2016-03-29 04:38:48 +02:00
|
|
|
import RecordsReducer from 'state/records/reducer';
|
2016-03-22 04:27:44 +01:00
|
|
|
|
2016-03-23 22:34:14 +01:00
|
|
|
// Sections
|
2016-03-30 23:45:54 +02:00
|
|
|
// eslint-disable-next-line no-unused-vars
|
2016-03-30 05:38:34 +02:00
|
|
|
import CampaignAdmin from 'sections/campaign-admin/index';
|
2016-03-23 22:34:14 +01:00
|
|
|
|
2016-03-16 01:30:39 +01:00
|
|
|
function appBoot() {
|
2016-03-30 23:45:54 +02:00
|
|
|
reducerRegister.add('config', ConfigReducer);
|
|
|
|
reducerRegister.add('schemas', SchemaReducer);
|
|
|
|
reducerRegister.add('records', RecordsReducer);
|
2016-03-22 04:27:44 +01:00
|
|
|
|
2016-03-30 23:45:54 +02:00
|
|
|
const initialState = {};
|
|
|
|
const rootReducer = combineReducers(reducerRegister.getAll());
|
|
|
|
const createStoreWithMiddleware = applyMiddleware(thunkMiddleware, createLogger())(createStore);
|
2016-03-16 01:30:39 +01:00
|
|
|
|
2016-03-30 23:45:54 +02:00
|
|
|
// TODO: The store needs to be passed into route callbacks on the route context.
|
|
|
|
window.store = createStoreWithMiddleware(rootReducer, initialState);
|
2016-03-22 04:27:44 +01:00
|
|
|
|
2016-03-30 23:45:54 +02:00
|
|
|
// Set the initial config state.
|
2016-04-07 13:15:53 +02:00
|
|
|
window.store.dispatch(configActions.setConfig(window.ss.config));
|
2016-03-16 01:30:39 +01:00
|
|
|
}
|
|
|
|
|
2016-03-30 23:45:54 +02:00
|
|
|
// TODO: This should be using `window.onload` but isn't because
|
|
|
|
// Entwine hooks are being used to set up the <Provider>.
|
|
|
|
// `window.onload` happens AFTER these Entwine hooks which means
|
|
|
|
// the store is undefined when the <Provider> is constructed.
|
2016-04-07 07:14:31 +02:00
|
|
|
$('body').entwine({ onadd: () => appBoot() });
|