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-22 04:27:44 +01:00
|
|
|
import * as configActions from '../state/config/actions';
|
|
|
|
import ConfigReducer from '../state/config/reducer';
|
|
|
|
|
2016-03-16 01:30:39 +01:00
|
|
|
function appBoot() {
|
2016-03-22 04:27:44 +01:00
|
|
|
reducerRegister.add('config', ConfigReducer);
|
|
|
|
|
2016-03-16 01:30:39 +01:00
|
|
|
const initialState = {};
|
|
|
|
const rootReducer = combineReducers(reducerRegister.getAll());
|
|
|
|
const createStoreWithMiddleware = applyMiddleware(thunkMiddleware, createLogger())(createStore);
|
|
|
|
|
2016-03-22 04:27:44 +01:00
|
|
|
// TODO: The store needs to be passed into route callbacks on the route context.
|
|
|
|
window.store = createStoreWithMiddleware(rootReducer, initialState);
|
|
|
|
|
|
|
|
// Set the initial config state.
|
|
|
|
configActions.setConfig(window.ss.config)(window.store.dispatch);
|
2016-03-16 01:30:39 +01:00
|
|
|
}
|
|
|
|
|
2016-03-22 04:27:44 +01: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.
|
|
|
|
$('body').entwine({ onadd: function () { appBoot(); } });
|