Files
grafana/public/app/store/configureStore.ts
Hugo Häggmark 133ddc9afb Feature: Adds connectWithCleanup HOC (#19629)
* Feature: Adds connectWithCleanup HOC

* Refactor: Small typings

* Refactor: Makes UseEffect run on Mount and UnMount only

* Refactor: Adds tests and rootReducer

* Refactor: Fixes adding of reducers on startup
2019-10-08 21:37:07 -07:00

34 lines
1.2 KiB
TypeScript

import { applyMiddleware, compose, createStore } from 'redux';
import thunk from 'redux-thunk';
import { createLogger } from 'redux-logger';
import { setStore } from './store';
import { StoreState } from 'app/types/store';
import { toggleLogActionsMiddleware } from 'app/core/middlewares/application';
import { addReducer, createRootReducer } from '../core/reducers/root';
export function addRootReducer(reducers: any) {
// 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);
}
export function configureStore() {
const composeEnhancers = (window as any).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
const logger = createLogger({
predicate: (getState: () => StoreState) => {
return getState().application.logActions;
},
});
const storeEnhancers =
process.env.NODE_ENV !== 'production'
? applyMiddleware(toggleLogActionsMiddleware, thunk, logger)
: applyMiddleware(thunk);
const store: any = createStore(createRootReducer(), {}, composeEnhancers(storeEnhancers));
setStore(store);
return store;
}