If you are into web development, you have probably heard of Redux. In case you didn’t; here is a great article that explains Redux – it even contains comics!
In a few lines I want to show you how we tried Redux and came to the conclusion that it DOES NOT fit for our project. This was in no way a disappointment, because here at PALFINGER we like to try new stuff and are not afraid of “making mistakes” – we don’t even see such explorations as mistakes – because this is how we learn. So in this article you might also see some aspects of our philosophy. Let’s get started.
Every framework ever
When we first heard about Redux, we loved the idea. Nevertheless every time we start to work with a new framework, we encounter challenges. But that’s part of the software development adventures, isn’t it? Therefore we have a simple rule about new technology:
Of course we collect some information, we talk to colleagues about their experiences and wait for a good opportunity to try the new technologies. But we are convinced that the only way to really get to know something is by trying it. That is one of the reasons why we held the largest HACKATHON in Austria. Also in our daily work we believe that we will learn a lot, in these sessions, even if we sometimes wish for a different outcome.
So I sat down and tried Redux in the context of our current project. I wanted to get a feeling for it. And I have to tell you the feeling wasn’t great. Now don’t get me wrong, I LOVE clean approaches. That’s what draw me to Redux. But there was just too much overhead in our context. It felt like this:
I noticed that we don’t have the typical side effects that Redux solves. If you compare a big MVC data flow with Redux data flow, you will immediately realize how much cleaner Redux is. But in our application (… and a lot of small angular applications) the flow of data doesn’t have many side effects. Therefore the Redux way adds more overhead than it solves.
Moving Redux to a higher level
So I thought to myself, maybe I just have to start at a higher level. Because Redux is perfect for handling side effects. I searched for parts of our application that influenced more than just one feature. Let me give you an example for this whole talk about context.
We have a Loader crane finder on our website.
The first part to your perfect crane is an industry selection. In the context of industry selection there are no side effects – there is a simple top-down event and data flow. Same for the next step the model selection. But if you select a certain industry and use case, namely “Municipal or public sector” and “Workman basket” we only want to show you cranes where a workman basket can be attached (duh…).
But now we have a side effect. Not only are industry and use case marked as selected, they also have an influence on another context.
You may think: Ah perfect for REDUX! … Yes and no. There are a few ideas that make perfect sense in this case, but others can’t be fulfilled. Redux works with reducers, actions and immutable states, but this would create too much overhead.
So we said to ourselves: “Let’s take the underlying idea and move it over here” (or into a service to be precise)
We created a state service that manages all interactions beyond the border of a context. This service was pretty simple, it didn’t have a reducer or selectors. It just had some variables, getter and setter, observables, the usual suspects… nothing new, but we had them all in one place.
We managed to have a single flow and a single truth for the application. Even if it wasn’t reaching through all layers, it was working on the level where we would need it the most.
So even if we didn’t end up using Redux, we learned a lot about Event- and Data-Flow, collect some new ideas and ended up improving our application. And that’s what we mean when we say: JUST DO IT ;)
P.S.: Since then a lot has changed on Redux, they managed to provide the possibility to combine small state handling implementations to one single-point-of-truth state. So we gave it a second chance, and wow, this changed a lot… but more of this in my next post.