import * as games from './games.actions' ; export interface State { loaded : boolean ; loading : boolean ; entities : Array < any > ; count : number ; page : number ; } ; const initialState = { loaded : false , loading : false , entities : [ ] , count : 0 , page : 1 } ; export function reducer ( state = initialState , action ) { switch ( action . type ) { case games . LOAD : { const page = action . payload ; return Object . assign ( { } , state , { loading : true , page : page == null ? state . page : page } ) ; } case games . LOAD_SUCCESS : { const games = action . payload [ 'results' ] ; const gamesCount = action . payload [ 'number_of_total_results' ] ; return Object . assign ( { } , state , { loaded : true , loading : false , entities : games , count : gamesCount } ) ; } case games . LOAD_FAILURE : { return Object . assign ( { } , state , { loaded : true , loading : false , entities : [ ] , count : 0 } ) ; } default : return state ; } } export const getEntities = ( state ) => state . entities ; export const getPage = ( state ) => state . page ; export const getCount = ( state ) => state . count ; export const getLoadingState = ( state ) => state . loading ;