I have been reading some on Redux. Most of what I read is combining redux with react. I use Angularjs. Is there a good reason to use Redux vs just managing state within angularjs scope and allowing angular to manage the bindings
To use Redux in the Angular framework, we can use the NgRx library. This is a reactive state management library. With NgRx, we can get all events (data) from the Angular app and put them all in the same place (Store).
Released by Google in 2010, AngularJS reached end-of-life (EOL) status on December 31, 2021. It means the long-term support will be ceased from the community.
Redux is a predictable state container designed to help you write JavaScript apps that behave consistently across client, server, and native environments and are easy to test. While it's mostly used as a state management tool with React, you can use it with any other JavaScript framework or library.
Although you can use ngReact, you also can create directives easily to make use of React. In Angular, directives are the best way to integrate "View Oriented" components to your angular application, and React is one framework much oriented to presentation/view layer.
Redux has benefits with Angular 1.x if you have a lot of shared state. In the Angular app I work on we have many pages with a shared model and several components that make (overlapping) changes to that model. It's not always easy to keep that data in sync or to have a standard way for changes to happen. Redux is a nice way to do that, though you could certainly implement something similar just using Angular services. The one-way data flow that Redux uses is easier (in my opinion) to follow than what you normally do in Angular. Conversely, introducing Redux probably hurts your ability to write really quick prototypes, since there's a bit more work to pass data around. That doesn't matter to me, but might matter to others.
The main principles of Redux still apply in Angular apps:
Using Redux means less of your code is Angular-centric. This means you have an easier upgrade path if you decide to not use Angular. Or even if you just want to migrate to Angular 2. How much easier is hard to say, though.
I don't think there's a ton of overlap due to Angular being more of a framework than a library, but there are things in Redux you can't take as much advantage of in Angular. You might know precisely what part of your app state is changing, but Angular is going run its digest cycle and check everything anyway. Angular 2 is better in that regard, though. You're going to have to jump through some hoops to make all your directives work with immutable data. And especially if you want to send every field a user changes through the Redux store, since ng-model wants to mutate the property you pass it.
Every app is different, but using Redux makes sense in the type of Angular apps I've worked on.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With