import { Action } from '@ngrx/store'; import { INIT_SCREEN_SIZE_REDUCER, InitScreenSizeReducerAction, SET_DESKTOP_CUTOFF_WIDTH, SET_SCREEN_SIZE, SET_TABLET_CUTOFF_WIDTH, SetCutoffWidthAction, SetScreenSizeAction, } from './screen-size-store.actions'; import { ScreenSizeStateInterface, } from './screen-size-state.interface'; const getDefaultState = (): ScreenSizeStateInterface => ({ desktopCutoffWidth: 0, screenSize: { height: 0, width: 0, }, tabletCutoffWidth: 0, }); export function screenSizeStoreReducer( state = getDefaultState(), action: Action, ): ScreenSizeStateInterface { switch (action.type) { case INIT_SCREEN_SIZE_REDUCER: return (action as InitScreenSizeReducerAction).state; case SET_SCREEN_SIZE: return { ...state, screenSize: (action as SetScreenSizeAction).screenSize, }; case SET_DESKTOP_CUTOFF_WIDTH: return { ...state, desktopCutoffWidth: (action as SetCutoffWidthAction).cutoffWidth, }; case SET_TABLET_CUTOFF_WIDTH: return { ...state, tabletCutoffWidth: (action as SetCutoffWidthAction).cutoffWidth, }; default: return state; } }