silverstripe-framework/admin/javascript/src/boot/index.js

37 lines
1.4 KiB
JavaScript
Raw Normal View History

2016-03-22 04:27:44 +01:00
import $ from 'jQuery';
import { combineReducers, createStore, applyMiddleware } from 'redux';
import thunkMiddleware from 'redux-thunk';
import createLogger from 'redux-logger';
import reducerRegister from 'reducer-register';
import * as configActions from 'state/config/actions';
import ConfigReducer from 'state/config/reducer';
import SchemaReducer from 'state/schema/reducer';
import RecordsReducer from 'state/records/reducer';
2016-03-22 04:27:44 +01:00
// Sections
// eslint-disable-next-line no-unused-vars
import CampaignAdmin from 'sections/campaign-admin/index';
function appBoot() {
reducerRegister.add('config', ConfigReducer);
reducerRegister.add('schemas', SchemaReducer);
reducerRegister.add('records', RecordsReducer);
2016-03-22 04:27:44 +01:00
const initialState = {};
const rootReducer = combineReducers(reducerRegister.getAll());
const createStoreWithMiddleware = applyMiddleware(thunkMiddleware, createLogger())(createStore);
// 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
// Set the initial config state.
window.store.dispatch(configActions.setConfig(window.ss.config));
}
// 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() });