Corner with reduction

I read some about Redux. Most of what I read combines reductions with reaction. I am using Angularjs. Is there a good reason to use Redux and just manage state in the angularjs scope and let angular manage bindings

+7
javascript angularjs angularjs-scope redux
source share
2 answers

Redux has advantages with Angular 1.x if you have a lot in common. In the Angular application I'm working on, we have many pages with a common model and several components that make (overlapping) changes to this model. It is not always easy to synchronize data or have a standard way to make changes. Redux is a good way to do this, although you can certainly implement something like this just by using Angular services. The one-way data flow that Redux uses is easier (in my opinion) to follow than you usually do in Angular. Conversely, implementing Redux is likely to hurt your ability to write really fast prototypes, as there is a bit more work to do with data transfer. It does not matter to me, but it may matter to others.

The basic principles of Redux are still applied in Angular applications:

  • A single source of truth (an object of a single state). As I said above, it’s easier for me to manage the state when it is in one place, and not managed in different areas or services of Angular. Soup soup is a real problem in some applications.
  • The condition is unchanged. This is where most of the friction happens with Angular, since Angular (and Javascript) make mutating data very light. But it will help you write safe code. Since you can change an immutable object by creating a copy, you can be more confident that any manipulations with the data that you do in the directive will not violate other directives. Conversely, you can expect other directives to not modify your data. All these changes pass through the central place (the object of a single state through gearboxes), therefore it is easier to find.
  • Changes are made using pure functions. I think this is useful in any JS application. The more code you have that doesn't have a bunch of side effects or structure dependencies, the easier it is for your application to understand and test. Many of our tests for Angular code have a bunch of application configuration templates. Comparing the gearbox is incredibly simple as it is just a Javascript function.

Using Redux means your code is smaller than Angular -centric. This means that you have an easier way to upgrade if you decide not to use Angular. Or even if you just want to upgrade to Angular 2. How much easier to say, though.

I don’t think there is a ton of overlap because Angular is more of a structure than a library, but there are things in Redux that you can't use in Angular. You know exactly what part of the state of your application is changing, but Angular will start its digest cycle and still check. Angular 2 is better in this regard. You will have to jump over several hoops so that all your directives work with immutable data. And especially, if you want to send each field, the user changes it through the Redux repository, since ng-model wants to change the property that you pass to it.

Each application is different, but using Redux makes sense in the type of Angular application I worked on.

+18
source share

Redux can be used with any javascript technology. As a result, you can integrate it into an Agular project. He is currently transforming the way applications are created. This allows a new way to conceive applications using a unidirectional data stream. As a result, it gives you better control over the state of your application and tools to troubleshoot issues related to data volatility. Take a look at this great tutorial on using Redux in Angular projects .

0
source share

All Articles