2020-01-13 01:03:22 -06:00
|
|
|
import { configureStore as reduxConfigureStore } from '@reduxjs/toolkit';
|
2019-06-03 06:40:33 -05:00
|
|
|
import { createLogger } from 'redux-logger';
|
2020-01-13 01:03:22 -06:00
|
|
|
import thunk from 'redux-thunk';
|
2019-10-08 23:37:07 -05:00
|
|
|
|
2018-11-05 09:54:48 -06:00
|
|
|
import { setStore } from './store';
|
2019-06-03 06:40:33 -05:00
|
|
|
import { StoreState } from 'app/types/store';
|
|
|
|
import { toggleLogActionsMiddleware } from 'app/core/middlewares/application';
|
2019-10-08 23:37:07 -05:00
|
|
|
import { addReducer, createRootReducer } from '../core/reducers/root';
|
2020-01-13 01:03:22 -06:00
|
|
|
import { buildInitialState } from '../core/reducers/navModel';
|
2019-10-04 07:24:47 -05:00
|
|
|
|
|
|
|
export function addRootReducer(reducers: any) {
|
2019-10-08 23:37:07 -05:00
|
|
|
// this is ok now because we add reducers before configureStore is called
|
|
|
|
// in the future if we want to add reducers during runtime
|
|
|
|
// we'll have to solve this in a more dynamic way
|
|
|
|
addReducer(reducers);
|
2019-10-04 07:24:47 -05:00
|
|
|
}
|
2018-10-16 08:36:33 -05:00
|
|
|
|
2018-07-09 03:28:20 -05:00
|
|
|
export function configureStore() {
|
2019-06-03 06:40:33 -05:00
|
|
|
const logger = createLogger({
|
2020-01-28 02:13:56 -06:00
|
|
|
predicate: getState => {
|
2019-06-03 06:40:33 -05:00
|
|
|
return getState().application.logActions;
|
|
|
|
},
|
|
|
|
});
|
2018-10-16 08:36:33 -05:00
|
|
|
|
2020-01-13 01:03:22 -06:00
|
|
|
const middleware = process.env.NODE_ENV !== 'production' ? [toggleLogActionsMiddleware, thunk, logger] : [thunk];
|
|
|
|
|
2020-01-28 02:13:56 -06:00
|
|
|
const store = reduxConfigureStore<StoreState>({
|
2020-01-13 01:03:22 -06:00
|
|
|
reducer: createRootReducer(),
|
|
|
|
middleware,
|
|
|
|
devTools: process.env.NODE_ENV !== 'production',
|
|
|
|
preloadedState: {
|
|
|
|
navIndex: buildInitialState(),
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2019-06-04 09:20:55 -05:00
|
|
|
setStore(store);
|
|
|
|
return store;
|
2018-07-09 02:17:38 -05:00
|
|
|
}
|