美文网首页
Redux复习

Redux复习

作者: 参商_70a0 | 来源:发表于2019-10-08 09:54 被阅读0次

Redux=Reducer+Flux


image.png

大致流程:
(1)component需要改变数据,通过store.dispatch(action)发一个action给store
(2)store将当前的state和action给Reducer
(3)Reducer基于action来通过拷贝原来的state,试图返回一个全新的state
(4)store会自动接收新state,并改变components ,store.subscribe
(this.handleStoreChange);可以监听state的值的改变,并执行相应函数
注意点:
store必须是唯一的。
只有store能改变state的内容。
reducer一定是纯函数(纯函数:给定固定的输入,一定有固定的输出)
关键词:
createStore
store.dispatch
store.getState
store.subscribe

相关文章

网友评论

      本文标题:Redux复习

      本文链接:https://www.haomeiwen.com/subject/pprmuctx.html