Adding the counter-list reducer

Let's start off with the reducer:

// counter/counter-list/counter-list.reducer.tsimport {  ADD_COUNTER_ITEM,  REMOVE_COUNTER_ITEM} from "./counter-list.constants";import { ActionPayload } from "../../action-payload";import { Counter } from "./counter.model";export function counterListReducer(state = [], action: ActionPayload<Counter>) {  switch (action.type) {    case ADD_COUNTER_ITEM:      return [...state, Object.assign(action.payload)];    case REMOVE_COUNTER_ITEM:      return state.filter(item => item.id !== action.payload.id);    default:      return state;  }}

This reducer supports two types, ADD_COUNTER_ITEM and REMOVE_COUNTER_ITEM, which will let us add and remove items from the list.

Get Architecting Angular Applications with Redux, RxJS, and NgRx now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.