Created
June 19, 2018 18:13
-
-
Save daniele-zurico/074271cbf7acfb9872f9ec1f1aed8b0e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function reducer(state = initialState, action: HeroesActions): State { | |
switch (action.type) { | |
case HeroesActionTypes.FetchHeroes: | |
return { | |
...state, | |
isLoading: true, | |
error: null | |
}; | |
case HeroesActionTypes.FetchHeroesSuccess: | |
return { | |
...state, | |
isLoading: false, | |
data: action.payload.results, | |
next: action.payload.next, | |
previous: action.payload.previous | |
}; | |
case HeroesActionTypes.FetchHeroesError: | |
return { | |
...state, | |
isLoading: false, | |
error: action.payload | |
}; | |
case HeroesActionTypes.ChangePage: | |
return { | |
...state, | |
page: action.payload === Pagination.NEXT ? ++state.page : --state.page | |
}; | |
default: | |
return state; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment