Commits
Matteo Perelli authored c99c8637e85
1 1 | import { combineReducers } from "@ngrx/store"; |
2 2 | import { routerReducer, RouterState } from "@ngrx/router-store"; |
3 3 | import { headerReducer, HeaderState } from './header/header.reducer'; |
4 4 | import { hostWindowReducer, HostWindowState } from "./shared/host-window.reducer"; |
5 5 | import { CoreState, coreReducer } from "./core/core.reducers"; |
6 + | import { storeFreeze } from 'ngrx-store-freeze'; |
7 + | import { compose } from "@ngrx/core"; |
6 8 | import { StoreActionTypes } from "./store.actions"; |
7 9 | |
10 + | import { EnvConfig } from '../config'; |
11 + | |
8 12 | export interface AppState { |
9 13 | core: CoreState; |
10 14 | router: RouterState; |
11 15 | hostWindow: HostWindowState; |
12 16 | header: HeaderState; |
13 17 | } |
14 18 | |
15 19 | export const reducers = { |
16 20 | core: coreReducer, |
17 21 | router: routerReducer, |
18 22 | hostWindow: hostWindowReducer, |
19 23 | header: headerReducer |
20 24 | }; |
21 25 | |
22 26 | export function rootReducer(state: any, action: any) { |
27 + | let output; |
23 28 | if (action.type === StoreActionTypes.REHYDRATE) { |
24 29 | state = action.payload; |
25 30 | } |
26 - | return combineReducers(reducers)(state, action); |
31 + | if (EnvConfig.production) { |
32 + | output = combineReducers(reducers)(state, action); |
33 + | } else { |
34 + | output = compose(storeFreeze, combineReducers)(reducers)(state, action); |
35 + | } |
36 + | return output; |
27 37 | } |
28 38 | |
29 39 | export const NGRX_CACHE_KEY = "NGRX_STORE"; |