React.js - flux vs全局事件总线 [英] React.js - flux vs global event bus
问题描述
在全球事件总线上使用Flux有什么优势?我认为只需要调度员:
What is the advantage of using Flux over a global event bus? I think the dispatcher is all that is needed:
- 组件向调度员发布带有数据的用户事件
- 调度程序执行订阅商店的处理程序
- 处理程序使用商店的更新属性发布更新事件
- 调度程序执行订阅的处理程序组件,并使用商店的更新属性更新组件状态
- component publishes 'user event' with data to the dispatcher
- dispatcher executes handler of the subscribed store
- handler publishes 'update event' with the store's updated properties
- dispatcher executes handler of the subscribed component, and updates component state with the store's updated properties
我在这里缺少什么,我不能没有Flux?
What am I missing here that I can't do without Flux?
推荐答案
我认为其他人对应用程序结构以及更改
事件所说的是很重要,但我应该补充一点:
I think what others have said about application structure and the change
event is important, but I should add this one thing:
调度员的 waitFor
方法是注册商店之间的最大区别与调度员和商店听全球事件总线。此方法允许您管理哪些商店在其他商店之前更新。当你希望StoreB首先看看StoreA在决定做什么之前所做的事情时,这变得至关重要。
The dispatcher's waitFor
method is the biggest difference between registering the stores with a dispatcher vs. the stores listening to a global event bus. This method lets you manage which stores update before others. And that becomes vital when you want StoreB to look first at what StoreA did before it decides what to do.
您可以将调度员视为一个全球事件总线 waitFor
方法,这有点准确。
You could think of the dispatcher as a global event bus with a waitFor
method, and that would be somewhat accurate.
这篇关于React.js - flux vs全局事件总线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!