Adding the counter-list reducer

Let's start off with the reducer:

// counter/counter-list/counter-list.reducer.ts

import {
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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.12.14