store = createStore(todoApp,[initialState])
初始化一个store
调用store.dispatch(action)
action是发生了什么的普通对象,比如:
{ type: 'LIKE_ARTICLE', articleId: 42 }; { type: 'FETCH_USER_SUCCESS', response: { id: 3, name: 'Mary' } }; { type: 'ADD_TODO', text: 'Read the Redux docs.'};
Redux store 调用传入的reducer函数
createStore时传入的todoApp是store调用的reducer函数
用Redux原生的
combineReducer()
函数,可以把多个reducer合并后传入storefunction todos(state = [], action) { // 省略处理逻辑... return nextState; } function visibleTodoFilter(state = 'SHOW_ALL', action) { // 省略处理逻辑... return nextState; } let todoApp = combineReducers({ todos, visibleTodoFilter })
当action触发后,combineReducer返回的todoApp会调用两个reducer,把结果合并成一个state树
Redux store 保存了combineReducer合并的todoApp所返回的完整state
这个state就是最新的state,所有订阅store.subscribe(listener)的监听器都会被调用