码迷,mamicode.com
首页 > 其他好文 > 详细

redux - rootRedux

时间:2018-06-25 15:00:24      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:ssi   red   pre   ons   port   ase   die   cat   redux   

1. split

const reducer = (state, action) => {
    switch (action.type) {
        case ‘ADD_RECIPE‘:
            return Object.assign(
                {}, state, {
                    recipes: state.recipes.concat({name : action.name})
            });
            
        case ‘ADD_INGREDIENT‘:
            const myIngredients = {
                        name : action.name,
                        quantity: action.quantity,
                        measure: action.measure,
                        recipe: action.recipe
                        };
            return Object.assign(
                {}, state, {
                    ingredients: state.ingredients.concat(myIngredients)
            });
            
    }
    return state;
}

1)  recipeReducer

export const recipeReducer = (recipes, action) => {
    switch (action.type) {
        case ‘ADD_RECIPE‘:
            return 
                recipes.concat({name : action.name});
            
    }
    return recipes;
}

 

redux - rootRedux

标签:ssi   red   pre   ons   port   ase   die   cat   redux   

原文地址:https://www.cnblogs.com/xiaobin-hlj80/p/9223914.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!