Merge branch 'master'
[arvados.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
12 const composeEnhancers =
13     (process.env.NODE_ENV === 'development' &&
14     window && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__) ||
15     compose;
16
17 export interface RootState {
18     auth: AuthState;
19     projects: ProjectState;
20     router: RouterState;
21 }
22
23 const rootReducer = combineReducers({
24     auth: authReducer,
25     projects: projectsReducer,
26     router: routerReducer
27 });
28
29
30 export default function configureStore(initialState: RootState, history: History) {
31     const middlewares: Middleware[] = [
32         routerMiddleware(history),
33         thunkMiddleware
34     ];
35     const enhancer = composeEnhancers(applyMiddleware(...middlewares));
36     return createStore(rootReducer, initialState!, enhancer);
37 }