特性
- 单一数据源
-
State是只读的
- 使用纯函数来执行修改 为了描述,action如何改变state tree ,需要编写reducers Reducers 只是一些纯函数
组成
action-事件
本质是一个对象
Reducer
本质是一个函数,用于 响应 发过来的actions,经过处理,把state 发送给Store
接收两个参数,一个初始化state, 一个action
Store
总结
store 通过createStore(reducer)创建store
reducer 是一个纯函数接收一个初始state,和action
function(state=initState,action)
action 是一个 包含type和对state修改的Object
项目中 通过store.dispatch(action) 来更新store
通过store.subscribe(()=>{})来监听store变更