Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Redux is just one piece of the puzzle. Let me try to explain the problem it solves. Let's say if you are building a complex SPA with lot of UI components in the view and state changes impacts several parts of the view. You can build this view in several ways:

* Plain javascript with jquery - We can surely achieve it but the code quickly becomes a soup of callbacks and events handlers. After a while the code becomes unmanageable. This is pretty much the approach you're suggesting with getters/setters.

* AngularJS's dirty checking is one solution. It works and the code scales in large teams but perf suffers in complex views due to costly digests. It doesn't provide a way to conditionally exclude a sub-view from the digest cycle. This will become the main bottleneck (for perf) as the application grows.

* React and Angular 2/4 - React (shouldcomponentupdate) and Angular 2/4 (onpush change detection) leverages immutability very well to cut down re-render cycles. This is where Redux shines with its immutable way of changing state. It's uni-directional flow is another great benefit to keep the entire flow predictable and maintainable.

I am not saying all these things are needed for every SPA app out there. But these optimizations are needed for complex and performance sensitive applications. Check this out - https://medium.com/@dan_abramov/you-might-not-need-redux-be4...

Also, I know keeping application state as a single state tree is nothing new. I started this side project (https://github.com/guptag/FinCharts) almost four years ago with React/Immutable.js without any state management libraries (recently moved to electron from nodewebkit). But this code won't scale in large teams (entire ui state is declared in one file, cannot extend the functionality like Redux's middleware support etc).




No, if you get/set methods that doesn't imply javascript with jquery! I am using React, but not ReactRouter or Redux. I hold my application state in a tree, and the tree nodes have get/set methods. My state tree is not immutable. I think "immutable way of changing state" is an oxymoron.


It depends on the complexity of the application. If I am happy with the performance profile with mutable state then going with immutable state is obviously an overkill. These optimizations matter when React spends lot of time diffing the virtual dom of the entire app component for every state change.

I don't have an example with mutable state but for React + Redux, click on the benchmark perf test page @ https://github.com/guptag/js-frameworks. With 1500 tickers added to the page and with an price update happening every 10ms, React/Redux updates the view within 5ms (on my machine) and consistently maintains 60fps. This is when React does the virtual diffing of only one ticker component whose state is changed and skipping the rest (because of React-Redux's immutability checks). It's going to take more time if React spends diffing the entire app for every update (unfortunately, I don't have a measurement with mutable state as I built this page to compare with AngularJS).

We can easily measure and make a call whether immutability is needed for an app or not.


How do you trace and replay state changes when debugging?


Not the one being asked, but I usually go with breakpoints in Dev Tools.


Breakpoints cannot replay. They can pause and continue playing.

The inability to examine a time series of data after-the-fact and resume from any point makes this approach significantly, significantly worse. Like, I've done it just as you have, and I'd under no circumstances go back. It's so bad that I've basically built action-pattern systems in other languages (before using Redux, actually).

Functional tooling and composition with managed side effects is fucking awesome and doing otherwise verges on footgunning if it doesn't camp right out there.


I guess you must be having a whole different set of problems than me. I also use Redux, have not found time travel to be a boost to my productivity. I choose Redux because of the simplicity around state management, and having it all centralised in a store is a nice pattern. (Don't really get other commenters claiming that this isn't new - I don't see the relevance).


None of these problems are unique to web development. How do you solve these problems in iOS? In iOS you use MVC, and the Application object holds the state as a tree. MVC has a better solution to all these problems.


I'll ask you the same question I asked the sibling: how do you trace and replay state changes during debugging?

('Cause this is why we use Redux.)


Being able to do so is certainly a cool feature. But I've built a lot of apps prior to Redux and never felt like state replays were a must for debugging.

There are various ways to debug state in a React app that uses setState. React devtools show each component's state, and you can combine that with breakpoint debugging as per to figure out how you got there.


Yeah, you can use breakpoints, but...that's awful. Like, it feels like crap to do, you end up stuck in half-transactions and other nonsense because you have no better options. The use of Redux (or any other functionally-oriented action-based state system, I was writing them in Java and C# long before I ever used Redux) enables powerful stuff that, yeah, might not be a "must"--but being a "must" and being a transformatively powerful tool that requires very little cognitive overhead to leverage aren't that far off.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: