Bloc VS Redux, who is the winner?

Reactive Programming and Functional Programming

The first difference I can tell about Redux and Bloc is what paradigm inspired these concepts. if you are using Redux, the first thing you will find is Redux will help us create state management that always can predict their behavior because Redux is immutable and pure function. immutable and pure function are a concept that we can found in functional programming. If you are using Bloc, that the first thing you will find is you have to create a stream function that will be observed, so when the stream gave new data, the observer will know. this observer pattern that using publish and subscribe are a concept that we can found in Reactive Programming.

One Store vs Many Blocs

when we are using Redux, because the goal of this concept is to create a global store that can be accessed everywhere, it makes sense that we only need to create one global store and not more than one global store. why we only need one global store? if we are using more than one global store then we will lose the consistency of the data we have. But if we are using Bloc, we will create many Blocs (if we need it) and we will distribute our data through all of our blocs.

Amount of Code you have to write

If you are a lazy developer that doesn’t want to write too many codes just for state management, I guess this section will be important for you. As I already said, when we use Redux, we have to build our store first, then embed it into the root component of your projects, after that, you have to create your reducers, events, and actions (optionally thunk). for every reducer, you have to build actions and events for the reducers. if you are starting from scratch, using Redux will be very overwhelming especially if you’re not familiar with it. but if you are using Bloc, we will create less code for our bloc to be used. Of course, even the code needed to write bloc is less than Redux, Bloc is much more complex for me because we need to understand the concept of the stream and observe concept, which very hard for me to understand, opposite with Redux that for me pretty straight forward and elegant.

Comparing Login Feature using Redux vs Bloc

for example of login feature, I will show how the login feature implemented on my PPL project using Flutter, Bloc, and Firebase. and for Redux, I will show you examples using React and Redux. For these two examples, I will just show you the Bloc/Redux section and not the whole Login feature.

actions.login.ts
reducer.login.ts
store
combining login reducer with another reducer
login_bloc.dart
login_event.dart
login_state.dart

Conclusion

in my own opinion i’am still a big fan of redux and not planning to stop using for another concepts. but we need to use right tool for right cases, so i think if you’re planning to making mobile apps with Flutter, maybe using Bloc is wise decision, because when you’re using Flutter, mostly people already using Bloc and the documentation of Bloc is already well documented, so you can make sure if you found obstacle, google and stackoverflow could help you. if you’re using redux in Flutter, there is nothing with it, but i already try using redux in Flutter but redux with Flutter is not to popular and i can’t make sure google and stackoverflow could always help you if you find obstacle.

Reference

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store