I'm trying to get a better understanding of the flux pattern Facebook introduced a while ago.

From what I understand the dispatchers dispatches every payload to all registered callbacks. Does anyone know what the main motivation behind this broadcast is? Why not use something more like an observer pattern and only send the actions to specific stores? Or am I misunderstanding something?


When a user interacts with a React view, the view propagates an action through a central dispatcher, to the various stores that hold the application's data and business logic, which updates all of the views that are affected.

For an example let's say we have two views: menu and content. They represent typical main menu and content area of a web page. When a menu item is clicked it triggers events through the dispatcher. The events are received and handled by the stores updating their data as needed. The stores then notify the views that they should rerender themselves.

As you said, the stores receive all the events from the dispatcher. As a benefit, this design is simple and needs no configuration per store. There is no need to register observers to receive events. And with observer you would also need to filter the events. The number of events dispatched is not an issue because there is one-to-one relation with views and stores and typically you have only a handful of views in the application. IMHO the observer design in this case would be far worse.

  • Thanks! Between stores and view on top of the hierarchy (those 'view-controllers'), they use a more observer style connection. In the examples they implement this trough Node's EventEmitter if I recall correctly. Why not use the same dispatcher style to register view-controllers as a kind of callback in the store? Why would you go for Observer in this situation? – Seneca Aug 27 '15 at 6:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.