Skip to content

Instantly share code, notes, and snippets.

@daniele-zurico
Created June 19, 2018 18:13
Show Gist options
  • Save daniele-zurico/074271cbf7acfb9872f9ec1f1aed8b0e to your computer and use it in GitHub Desktop.
Save daniele-zurico/074271cbf7acfb9872f9ec1f1aed8b0e to your computer and use it in GitHub Desktop.
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