Tips For a Better Redux Architecture: Lessons for Enterprise Scale

Hashnode Original

Comments (8)

Write your comment

This comment has received 2 appreciations.

If you were using redux-define you could reduce the boilerplate of defining action types.

Especially when using status suffixes like ERROR or SUCCESS, it can make a big difference.

Turning your example

export const ADD_TODO = 'todos/ADD_TODO'
export const ADD_TODO_SUCCESS = 'todos/ADD_TODO_SUCCESS'
export const ADD_TODO_FAILURE = 'todos/ADD_TODO_FAILURE'


export const ADD_TODO = defineAction('ADD_TODO', [SUCCESS, FAILURE], 'todos');

Yes it's mine. I should have mentioned that. I use it with redux-actions and redux-saga like the example in the readme. And really like the now obvious separation between actions and status updates. While having less boilerplate.

Write a reply...

This comment has received 1 appreciation.

Very nice post @michaelgilley I'm implementing a similar approach you proposed for my PoC.

Write a reply...

Thanks a lot! I've been struggling to maintain a disorganized app for a long time, but I think the concepts you have presented here will do the trick!

Write a reply...

For importing module across features i like Jack hsu ( implementation.

Yes, that scheme is very close to Ducks as well and there are several different ways to stash the modular components of a Redux app. Perhaps the most important is uniformity in design across modules. Also, while I do like the separation of each type into separate files this would also have the disadvantage of even more boilerplate code/structure to manage per module. Thanks for the post!

Write a reply...

Question regarding this statement:

Specifically, we are currently passing every prop needed down from the Container level. These props are either defined in the Container or injected via the connect HoC. While this makes organization simple it also means every change or addition of a prop equates to changes to every JSX component in the tree. This gets tiring.

Do you have some kind of solution for this?

I find myself using one container that is connected to Redux store and passing everything to my children. Result of that is a lot of returning in mapStateToProps and mapDispatchToProps.

One logical solution for me is to separate one big container to maybe 2-3 smaller containers for easier tracking of what is imported and connected.

Is there anything else you can advise?

Thanks! :)

Hi @vblazenka . We use many different containers and at each container level have a separate module. Props are not passed into Containers from parents though (except from Providers like react-intl, Redux, or React-router). It makes for a much flatter architecture than having only 1 container BUT there is still the problem of passing things down multiple levels when components get deep. I'm not sure what the fix for this would be and using context is out of the picture. I just might be the price paid for the other benefits of such a design....

Write a reply...

Thanks for the great post Michael. What if two different modules have common components? How would you organize that?

Thank you @cdharrison. If you have common components (for example forms or a common header) you'd move those out to their own module. We have a few of those global modules like FormElements that don't need a module dir/file but live at the root level anyway and are imported where needed. In these cases the root App module does not import anything from these modules. Great question!

Write a reply...

Great post hugely helpful application-skeleton while developing large applications.

Write a reply...

This all can be done much simpler and more declarative than Redux Saga. You have to look at Cerebral's signals and it's excellent function tree, it can be used not only in Cerebral, but also in Redux or Mobx.

Thanks for the tip @hipertracker. I haven't looked at cerebral yet. I'll have to read more about it and see how it compares.

Write a reply...

loading ...