reducer(state, action) → store.dispatch(action) → final state
store 管理狀態(tài)的盒子 → getState() dispatch(action)
分發(fā)
→ reducer 用來修改state的方法,返回state
→ action 改變的狀態(tài),{type: 'xxx'甘邀,text: ‘xxx’}
import redux from 'redux';
const reducer = function (state, action) {
switch (action.type) {
case 'add_Todo':
return state.concat(action.text);
default:
return state;
}
};
const addTodo = function (text) {//actionAreator
return {
type: 'add_Todo',
text: text
};
};
const store = redux.createStore(reducer, []);
store.dispatch(addTodo('xxx'));
store.getState();