import { updateMessage , updateWindowIds , finishGetWindowIds } from '../actions/' ; import { ActionType , AppState } from '../Types' ; type Actions = ReturnType < typeof updateMessage > | ReturnType < typeof updateWindowIds > | ReturnType < typeof finishGetWindowIds > ; const InitialState = { id : window . location . hash ? Number ( window . location . hash . replace ( '#' , '' ) ) : 0 , windowIds : [ ] , message : '' } ; if ( InitialState . id ) { document . title += ` [${ InitialState . id }]` ; } param state param action returns export const reducer = ( state = InitialState , action ) => { switch ( action . type ) { case ActionType . UpdateMessage : return Object . assign ( { } , state , { message : action . payload . message } ) ; case ActionType . UpdateWindowIds : return Object . assign ( { } , state , { windowIds : action . payload . windowIds . filter ( ( id ) => id !== state . id ) } ) ; case ActionType . GetWindowIds : return Object . assign ( { } , state , { windowIds : action . payload . windowIds . filter ( ( id ) => id !== state . id ) } ) ; default : return state ; } } ;