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.