它们如何在一起工作?
最后更新于:2022-04-01 04:30:53
## 它们如何在一起工作?
接下来看看这些角色是如何在一起工作的。
### 开始
首先在应用启动时:启动只有一次。
1. Store 告知 Dispatcher 只要有 action 产生就通知它。

2. Controller View 从 Store 中获取最新的 state。
3. 当 Controller View 接到来自 store 的 state,就将其传递给它所管辖的子 View 去渲染。

4. Controller View 同时让 store 在 state 变化的时候通知自己。

### 数据流
应用启动后,就准备好接受用户的输入了。现在我们让用户做一些操作,触发一个 action。

用户交互我们就产生一次数据流。
1. View 告知 Action Creator 准备一个 action。

2. Action Creator 做好 action 并将其发送给 Dispatcher。

3. Dispatcher 按照顺序将 action 传递给 store。每一个 store 都会受到所有的 action 通知,然后自行觉得是否对这个 action 做出响应,更新 state。

4. 一旦 store 更新 state 完毕,就会告知订阅了该 store 的 controller view。
5. 这些 controller view 就会向 store 请求更新了的 state。

6. 从 store 中获得 state 之后,view controller 将会让它所管辖的子 view 渲染新的 state。

好了,这些就是我对 Flux 的理解,希望能够帮助到你!