Skip to content

Commit

Permalink
Course Project: Adding logic to the reducer
Browse files Browse the repository at this point in the history
  • Loading branch information
Renante D. Entera committed Aug 29, 2020
1 parent 288fbc0 commit 3ad90db
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions course-project/src/app/shopping-list/shopping-list.reducer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Action } from '@ngrx/store';

import { Ingredient } from '../shared/ingredient.model';

const initialState = {
ingredients: [
new Ingredient('Apples', 5),
new Ingredient('Tomatoes', 10),
]
};

export function shoppingListReducer(state = initialState, action: Action) {
switch (action.type) {
case 'ADD_INGREDIENT':
return {
...state,
ingredients: [...state.ingredients, action]
};
}
}

0 comments on commit 3ad90db

Please sign in to comment.