其他分享
首页 > 其他分享> > redux 的工作流程

redux 的工作流程

作者:互联网

redux 是什么?

Redux 是 JavaScript 应用的状态容器,提供可预测的状态管理  

redux 设计和使用的三大原则:

- state以单一对象存储在store对象中(整个应用的全局state被储存在一棵 object tree 中,并且这个 object tree 只存在于唯一一个 store中) - 提供 [`getState()`]方法获取 state; - 提供 [`dispatch(action)`]方法更新 state; - 通过 [`subscribe(listener)`]注册监听器; - 通过 [`subscribe(listener)`]返回的函数注销监听器 - state只读(唯一改变 state 的方法就是触发action,action 是一个具有type属性的用于描述已发生事件的普通对象.) - 使用纯函数reducer执行state更新(为了描述 action 如何改变 state tree,你需要编写纯的reducers)

redux数据流(参考官网)

component【UI】 --> dispatch(action) --> reducer --> subscribe --> getState --> component【UI】

标签:subscribe,--,流程,tree,工作,state,action,redux
来源: https://www.cnblogs.com/dancefinger/p/15748428.html