import { createSelector , createFeatureSelector , ActionReducer , MetaReducer , Action , ActionReducerMap , } from '@ngrx/store' ; import { environment } from '../../environments/environment' ; import * as fromRouter from '@ngrx/router-store' ; import { Params } from '@angular/router' ; import { getSelectors , RouterReducerState } from '@ngrx/router-store' ; /**
 * Every reducer module's default export is the reducer function itself. In
 * addition, each module should export a type or interface that describes
 * the state of the reducer plus any selector functions. The `* as`
 * notation packages up all of the exports into a single object.
 */ import * as fromLayout from './../core/reducers/layout.reducer' ; import { InjectionToken } from '@angular/core' ; /**
 * As mentioned, we treat each reducer like a table in a database. This means
 * our top level state interface is just a map of keys to inner state types.
 */ export interface State { [ fromLayout . layoutFeatureKey ] : fromLayout . State ; router : fromRouter . RouterReducerState < any > ; } /**
 * 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 < State , Action > > ( 'Root reducers token' , { factory : ( ) => ( { [ fromLayout . layoutFeatureKey ] : fromLayout . reducer , router : fromRouter . routerReducer , } ) , } ) ; export function logger ( reducer ) { 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 ; } ; } /**
 * By default, @ngrx/store uses combineReducers with the reducer map to compose
 * the root meta-reducer. To add more meta-reducers, provide an array of meta-reducers
 * that will be composed to form the root meta-reducer.
 */ export const metaReducers = ! environment . production ? [ logger ] : [ ] ; /**
 * Layout Selectors
 */ export const selectLayoutState = createFeatureSelector < State , fromLayout . State > ( fromLayout . layoutFeatureKey ) ; export const selectLoaded = createSelector ( selectLayoutState , fromLayout . selectLoaded ) ; export const selectAlertInfo = createSelector ( selectLayoutState , fromLayout . selectAlertInfo ) ; export const selectUsername = createSelector ( selectLayoutState , fromLayout . selectUsername ) ; export const selectMuteState = createSelector ( selectLayoutState , fromLayout . selectIsMute ) ; /**
 * Router Selectors
 */ export const selectRouter = createFeatureSelector < State , fromRouter . RouterReducerState > ( 'router' ) ; export const { selectCurrentRoute , selectFragment , selectQueryParams , selectQueryParam , selectRouteParams , selectRouteParam , selectRouteData , selectUrl , } = getSelectors ( selectRouter ) ; export const selectRouteNestedParams = createSelector ( selectRouter , ( router ) => { let currentRoute = router ?. state ?. root ; let params = { } ; while ( currentRoute ?. firstChild ) { currentRoute = currentRoute . firstChild ; params = { ... params , ... currentRoute . params , } ; } return params ; } ) ; export const selectRouteNestedParam = ( ) => createSelector ( selectRouteNestedParams , ( params ) => params ) ;