Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React.js - flux vs global event bus

What is the advantage of using Flux over a global event bus? I think the dispatcher is all that is needed:

  1. component publishes 'user event' with data to the dispatcher
  2. dispatcher executes handler of the subscribed store
  3. handler publishes 'update event' with the store's updated properties
  4. dispatcher executes handler of the subscribed component, and updates component state with the store's updated properties

What am I missing here that I can't do without Flux?

like image 786
tldr Avatar asked Apr 15 '15 06:04

tldr


People also ask

Should I use flux or Redux?

The primary difference of Flux vs Redux is that Flux includes multiple Stores per app, but Redux includes a single Store per app. Rather than placing state information in multiple Stores across the application, Redux keeps everything in one region of the app.

What is the primary advantage of using flux implementation in React?

Main Features of Flux Flux keeps code predictable when compared to other MVC frameworks. Developers can build applications without being bothered about complicated interactions between data resources. Flux boasts of a better structured data flow – unidirectional. Being unidirectional is the central feature of Flux.

What is the use of flux in React JS?

Flux uses a unidirectional data flow pattern to solve state management complexity. Remember it is not a framework – rather it's more of a pattern that targets to solve the state management issue.

Is Flux a state management library?

Facebook's Flux is the original state management library for React, although it is more of a pattern than a library or framework. While there is an NPM package for Flux provided by Facebook, its offerings are quite sparse, and most of the heavy lifting is left to the application developer.


1 Answers

I think what others have said about application structure and the change event is important, but I should add this one thing:

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.

You could think of the dispatcher as a global event bus with a waitFor method, and that would be somewhat accurate.

like image 80
fisherwebdev Avatar answered Oct 28 '22 01:10

fisherwebdev