Added central action for navigation
[arvados-workbench2.git] / src / store / store.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { createStore, applyMiddleware, compose, Middleware, combineReducers } from 'redux';
6 import { routerMiddleware, routerReducer, RouterState } from "react-router-redux";
7 import thunkMiddleware from 'redux-thunk';
8 import { History } from "history";
9 import projectsReducer, { ProjectState } from "./project/project-reducer";
10 import authReducer, { AuthState } from "./auth/auth-reducer";
11 import collectionsReducer, { CollectionState } from "./collection/collection-reducer";
12
13 const composeEnhancers =
14     (process.env.NODE_ENV === 'development' &&
15     window && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__) ||
16     compose;
17
18 export interface RootState {
19     auth: AuthState;
20     projects: ProjectState;
21     collections: CollectionState;
22     router: RouterState;
23 }
24
25 const rootReducer = combineReducers({
26     auth: authReducer,
27     projects: projectsReducer,
28     collections: collectionsReducer,
29     router: routerReducer
30 });
31
32
33 export default function configureStore(initialState: RootState, history: History) {
34     const middlewares: Middleware[] = [
35         routerMiddleware(history),
36         thunkMiddleware
37     ];
38     const enhancer = composeEnhancers(applyMiddleware(...middlewares));
39     return createStore(rootReducer, initialState!, enhancer);
40 }