首页 > 其他 > 详细

Redux 理解

时间:2017-05-08 01:01:13      阅读:289      评论:0      收藏:0      [点我收藏+]

1: state 就像 model

{
    todos: [{
        text: ‘Eat food‘,
        completed: true
    }, {
        text: ‘Exercise‘,
        completed: false
    }],
    visibilityFilter: ‘SHOW_COMPLETED‘
}

 

2: action, 普通的 javascript 对象, 用来描述发生了什么

{ type: ‘ADD_TODO‘, text: ‘Go to swimming pool‘ }
{ type: ‘TOGGLE_TODO‘, index: 1 }
{ type: ‘SET_VISIBILITY_FILTER‘, filter: ‘SHOW_ALL‘ }

 

3. 为了把 action 和 state 串起来, 就是 reducer, 例如下面:

function todos(state = [], action) {
    switch (action.type) {
        case ‘ADD_TODO‘:
            return state.concat([{ text: action.text, completed: false }]);
        default:
            return state;
    }
}

 

Redux 理解

原文:http://www.cnblogs.com/zhengming2016/p/6822918.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!