使用多个Dispatchers进行反应

时间:2015-10-01 08:33:48

标签: reactjs flux

我有一个反应应用程序,我想在我的应用程序的多个部分中使用“Dispatcher架构”,它们彼此完全无关。

(一个是传统的组件/操作/存储处理,另一个是一些可互换的插件,可以通过这种方式注册到Dispatchers,将它与主应用程序分离。)

由于这两个部分彼此无关,我想为它使用两个不同的调度员。

是否可能,或者由于Dispatcher是单例,我只能使用一个?

1 个答案:

答案 0 :(得分:5)

Speaking from my experience with Vanilla Flux:

It's purposely a singleton because you want all your Actions to go through the same gatekeeper that disburses the update to all the stores that need to know.

This helps developers think about their code flow as uni-directional. With multiple dispatchers talking to multiple stores the code flow will once again become entangled and a easy mental model would break down.

Note: I know this answer is late, but I'm sure many other newcomers will at some point have this question.