Created
June 16, 2017 18:46
-
-
Save phuchle/987752a161fb1a6613f7958208c1c1e4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/////////////////// | |
// Begin Recipes // | |
/////////////////// | |
import { ADD_RECIPE, REMOVE_RECIPE } from '../actions'; | |
const defaultRecipes = [ | |
{ | |
title: 'Pumpkin Pie', | |
ingredients: 'Pumkin Puree, Sweetened Condensed Milk, Eggs, Pumkin Pie Spice, Pie Crust' | |
}, | |
{ | |
title: 'Spaghetti', | |
ingredients: 'Noodles, Pasta Sauce, Meatballs' | |
}, | |
{ | |
title: 'Peanut Butter Mug Cake', | |
ingredients: 'Peanut Butter, Eggs, Baking Powder, Sugar' | |
} | |
]; | |
const Recipes = (state = defaultRecipes, action) => { | |
switch (action.type) { | |
case ADD_RECIPE: | |
return [ | |
...state, | |
action.recipe | |
] | |
case REMOVE_RECIPE: | |
return state.filter(recipe => recipe.name !== action.recipe.name ); | |
default: | |
return state; | |
} | |
} | |
export default Recipes; | |
/////////////////////// | |
// Begin RootReducer // | |
/////////////////////// | |
import { combineReducers } from 'redux'; | |
import Recipes from './Recipes'; | |
const RootReducer = combineReducers({ | |
recipes: Recipes | |
}); | |
export default RootReducer; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment