I am playing around with ngrx store, deleting, fetching, and editing elements in array works just fine, but the problem is when I first time insert object into an array like {id: 1, name: 'Potato', quantity: 2}, two exactly same objects are inserted unless i filter it like in reducer below.
State
export const initialShoppingState: ShoppingState = {
shoppingList: [],
};
This one works but probably i shouldn't filter it to prevent adding same object
on(ShoppingAction.shoppingItemAdded, (state, { shoppingItem }) => {
console.log(state);
return ({ ...state, shoppingList: [...state.shoppingList.filter((item) => item.id !== shoppingItem.id), shoppingItem] });
}),
This one adds first item two times, next items items only once.
on(ShoppingAction.shoppingItemAdded, (state, { shoppingItem }) => {
console.log(state);
return ({ ...state, shoppingList: [...state.shoppingList.concat(shoppingItem)] });
}),