import { Hero } from '../../core' ; import * as fromHeroes from '../actions/heroes.actions' ; export interface HeroesState { data : Hero [ ] ; loaded : boolean ; loading : boolean ; } export const initialHeroesState = { data : testHeroes ( ) , loaded : false , loading : false } ; param state param action export function reducer ( state = initialHeroesState , action ) { switch ( action . type ) { case fromHeroes . LOAD_HEROES : { return { ... state , loading : true } ; } case fromHeroes . LOAD_HEROES_SUCCESS : { return { ... state , data : action . payload , loaded : true , loading : false , } ; } case fromHeroes . LOAD_HEROES_ERROR : { return { ... state , loaded : false , loading : false , } ; } } return state ; } function testHeroes ( ) { return [ { id : 11 , name : 'Maxwell Smart' , saying : 'Missed it by that much.' } , { id : 12 , name : 'Bullwinkle J. Moose' , saying : 'Watch me pull a rabbit out of a hat.' } ] ; }