Updating the reducer

At this point we take our existing reducer.ts file and add what we need to support adding a product:

// products.reducer.tsimport {  FETCHING_PRODUCTS_SUCCESSFULLY,  FETCHING_PRODUCTS_ERROR,  FETCHING_PRODUCTS,  ADD_PRODUCT,  ADD_PRODUCT_SUCCESSFULLY,  ADD_PRODUCT_ERROR} from "./product.constants";import { Product } from "./product.model";const initialState = {  loading: false,  list: [],  error: void 0}export interface ProductsState {  loading: boolean;  list: Array<Product>,  error: string;}function addProduct(list, product) {  return [ ...list, product];}export function productsReducer(state = initialState, action) {  switch(action.type) {    case FETCHING_PRODUCTS_SUCCESSFULLY:      return { ...state, list: action.payload, loading: false ...

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.