Skip to content

Instantly share code, notes, and snippets.

@matthieu-D
Created August 18, 2017 11:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthieu-D/4225b0b7ecc679c01a2f05df017b7919 to your computer and use it in GitHub Desktop.
Save matthieu-D/4225b0b7ecc679c01a2f05df017b7919 to your computer and use it in GitHub Desktop.
export function colorReducer(state: ColorListState = INITIAL_STATE,
action: Action): ColorListState {
switch (action.type) {
case ColorActions.LOAD_COLORS:
return {
colorList: ['red', 'green']
};
case ColorActions.ADD_COLORS:
const colorAddAction = action as ColorAddAction;
return {
colorList: [...state.colorList, ...colorAddAction.payload]
};
case ColorActions.REMOVE_LAST_COLOR:
return {
colorList: state.colorList.slice(0, state.colorList.length -1)
};
}
return state;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment