Redux: One vs Mulitple reducers

Created on 4 May 2017  路  4Comments  路  Source: reduxjs/redux

Hi!

I come from the Elm-comunity and in Elm, every application has its view, its model and its state and basically takes very similar approach, IMO, to solving problems as redux does.

Anyway, I found myself struggling with the idea of multiple reducers. In Elm I am used to make a separate file for all the actions (Messages), a separate file for "react" (View), a separate one for state (Model), and a separate one for all the reducers (Update).

Every possible action gets covered inside Update file and Update file cannot be spread trough multiple files, keeping all the logic in one place.

On the other hand, Redux encourages making multiple separate files for reducers and later on combining them with combineReducers, which I found very confusing and more than less a disadvantage rather than an advantage.

If i get things right, each reducers only gets the part it's "responsible" for and is able to do something with it and different reducers cannot access other state-properties/properties of other reducers.

Cons of doing this IMO:

  1. Function from reducer A may need info about information from reducer B, but cannot be accessed because of this.
  2. More files lead to more mess and unintentional errors.
  3. Unnecessary code splitting.
    ...

What are the pros then of splitting code or am I not seeing something here?

Most helpful comment

That said, you may want to read through the "Structuring Reducers" section I wrote for the docs, which discuss several aspects of reducer logic, as well as the Redux FAQ entry on sharing state between reducers.

I'm also currently writing a blog post that will discuss what technical limitations Redux actually requires, vs how you're _intended_ to use Redux, vs how it's _possible_ to use Redux. "Slice reducers" is one of the items I discuss in that post. If you're interested, keep an eye on my blog at http://blog.isquaredsoftware.com - probably will have the post up early next week.

All 4 comments

This is a bug tracker, not a support system. For usage questions, please use Stack Overflow or Reactiflux. Thanks!

That said, you may want to read through the "Structuring Reducers" section I wrote for the docs, which discuss several aspects of reducer logic, as well as the Redux FAQ entry on sharing state between reducers.

I'm also currently writing a blog post that will discuss what technical limitations Redux actually requires, vs how you're _intended_ to use Redux, vs how it's _possible_ to use Redux. "Slice reducers" is one of the items I discuss in that post. If you're interested, keep an eye on my blog at http://blog.isquaredsoftware.com - probably will have the post up early next week.

@markerikson Can you please share the "slice reducers" article

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ilearnio picture ilearnio  路  3Comments

ms88privat picture ms88privat  路  3Comments

mickeyreiss-visor picture mickeyreiss-visor  路  3Comments

captbaritone picture captbaritone  路  3Comments

parallelthought picture parallelthought  路  3Comments