Skip to content

Instantly share code, notes, and snippets.

@phuchle
Created June 16, 2017 18:46
Show Gist options
  • Save phuchle/987752a161fb1a6613f7958208c1c1e4 to your computer and use it in GitHub Desktop.
Save phuchle/987752a161fb1a6613f7958208c1c1e4 to your computer and use it in GitHub Desktop.
///////////////////
// 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