I just picked up a React/Flux app and I'm new to the technology stack. One of the things that's throwing me off is that just about every tutorial I view on this stack very clearly defines Dispatchers as a necessary component.

I'm wondering if the previous developer chose not to use them, or if the notation he used actually takes the place of the dispatcher.

Is the following block of code a valid replacement of Dispatcher components?

update(id, info, photo) {
  return dispatch => (
    update(id, info)
      .then(res => this._uploadPhoto(res, photo))
      .then(res => dispatch(res.data))
      .catch(err => this.updateError(err))

The code is completely Dispatcher-agnostic. You could supply any number of interesting (or boring) dispatch functions as the argument to the returned function. We have some similar functions in our React/Redux stack.

It's not a dispatcher or dispatch component in its own right.

| improve this answer | |

To cite from the Facebook documentation:

Flux is the application architecture that Facebook uses for building client-side web applications. It complements React's composable view components by utilizing a unidirectional data flow. It's more of a pattern rather than a formal framework [...]

In the Flux architecture as described by Facebook, a dispatcher is one of the main parts. So you need a dispatcher if you are to respect their definition of Flux.

But there are multiple Flux implementations: Redux, Alt, Fluxxor, Lux, Reflux, OmniscientJS, McFly, Fluxible, Delorean, Fluxy, etc.

In the Reflux implementation for example, the dispatcher does not exist as a distinct part of the pattern. Instead the dispatcher is moved into the actions themselves.

It's hard to tell from the code you posted if that's acting as a dispatcher, but maybe the previous developer liked the Flux idea but not the implementation?! So he implemented his own?!

| improve this answer | |
  • 1
    To be fair, the link shows an absolutely massive shift for Redux, with more than 20x as many downloads as the next guy and I'd have to say about double everybody else combined. – DeadMG Dec 19 '16 at 21:22

The answer depends on your flux implementation.

This looks like an action creator for redux-thunk

| improve this answer | |

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.