mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
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
This commit is contained in:
@@ -1,46 +1,22 @@
|
||||
import { createStore, applyMiddleware, compose, combineReducers } from 'redux';
|
||||
import { applyMiddleware, compose, createStore } from 'redux';
|
||||
import thunk from 'redux-thunk';
|
||||
import { createLogger } from 'redux-logger';
|
||||
import sharedReducers from 'app/core/reducers';
|
||||
import alertingReducers from 'app/features/alerting/state/reducers';
|
||||
import teamsReducers from 'app/features/teams/state/reducers';
|
||||
import apiKeysReducers from 'app/features/api-keys/state/reducers';
|
||||
import foldersReducers from 'app/features/folders/state/reducers';
|
||||
import dashboardReducers from 'app/features/dashboard/state/reducers';
|
||||
import exploreReducers from 'app/features/explore/state/reducers';
|
||||
import pluginReducers from 'app/features/plugins/state/reducers';
|
||||
import dataSourcesReducers from 'app/features/datasources/state/reducers';
|
||||
import usersReducers from 'app/features/users/state/reducers';
|
||||
import userReducers from 'app/features/profile/state/reducers';
|
||||
import organizationReducers from 'app/features/org/state/reducers';
|
||||
import ldapReducers from 'app/features/admin/state/reducers';
|
||||
|
||||
import { setStore } from './store';
|
||||
import { StoreState } from 'app/types/store';
|
||||
import { toggleLogActionsMiddleware } from 'app/core/middlewares/application';
|
||||
|
||||
const rootReducers = {
|
||||
...sharedReducers,
|
||||
...alertingReducers,
|
||||
...teamsReducers,
|
||||
...apiKeysReducers,
|
||||
...foldersReducers,
|
||||
...dashboardReducers,
|
||||
...exploreReducers,
|
||||
...pluginReducers,
|
||||
...dataSourcesReducers,
|
||||
...usersReducers,
|
||||
...userReducers,
|
||||
...organizationReducers,
|
||||
...ldapReducers,
|
||||
};
|
||||
import { addReducer, createRootReducer } from '../core/reducers/root';
|
||||
|
||||
export function addRootReducer(reducers: any) {
|
||||
Object.assign(rootReducers, ...reducers);
|
||||
// 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 rootReducer = combineReducers(rootReducers);
|
||||
|
||||
const logger = createLogger({
|
||||
predicate: (getState: () => StoreState) => {
|
||||
return getState().application.logActions;
|
||||
@@ -51,7 +27,7 @@ export function configureStore() {
|
||||
? applyMiddleware(toggleLogActionsMiddleware, thunk, logger)
|
||||
: applyMiddleware(thunk);
|
||||
|
||||
const store = createStore(rootReducer, {}, composeEnhancers(storeEnhancers));
|
||||
const store: any = createStore(createRootReducer(), {}, composeEnhancers(storeEnhancers));
|
||||
setStore(store);
|
||||
return store;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user