import { Type, InjectionToken } from '@angular/core'; import { ActionReducer, MetaReducer, Action, ActionReducerMap } from '@ngrx/store'; import * as fromRouter from '@ngrx/router-store'; import { storeFreeze } from 'ngrx-store-freeze'; import { environment } from '../../environments/environment'; import * as AccountStore from './account'; export interface State { router: fromRouter.RouterReducerState; account: AccountStore.State; } /** * Our state is composed of a map of action reducer functions. * These reducer functions are called with each dispatched action * and the current or initial state and return a new immutable state. */ export const ROOT_REDUCERS = new InjectionToken< ActionReducerMap >('Root reducers token', { factory: () => ({ router: fromRouter.routerReducer, account: AccountStore.reducers }) }); export const effects: Type[] = [...AccountStore.effects]; export function logger(reducer: ActionReducer): ActionReducer { return (state, action) => { const result = reducer(state, action); console.groupCollapsed(action.type); console.log('prev state', state); console.log('action', action); console.log('next state', result); console.groupEnd(); return result; }; } export const metaReducers: MetaReducer[] = !environment.production ? [logger, storeFreeze] : []; export const AccountSelector = AccountStore.selectors( (state: State) => state.account );