Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using ngrx with Angular

Tags:

angular

ngrx

We are using ngrx with Angular2 in our current project. Basically ngrx is reactive extension of Redux. ngrx provide single source of truth and the data can be access from everywhere.

We can handle all these scenarios using global services but why to write same code that is already available and tested.

like image 802
Ramesh Rajendran Avatar asked Apr 25 '18 06:04

Ramesh Rajendran


People also ask

Is NgRx good for Angular?

NgRx is a popular solution in the Angular ecosystem if you are building complex web applications with sophisticated state management. Characteristics of the need for NgRx are many user interactions and multiple data sources. NgRx is a good choice, if: the state should be accessed by many components and services.

Is NgRx part of Angular?

Ngrx is a group of Angular libraries for reactive extensions. Ngrx/Store implements the Redux pattern using the well-known RxJS observables of Angular 2. It provides several advantages by simplifying your application state to plain objects, enforcing unidirectional data flow, and more.

When should you not use NgRx?

When should you not use NgRx? Never use NgRx if your application is a small one with just a couple of domains or if you want to deliver something quickly. It comes with a lot of boilerplate code, so in some scenarios it will make your coding more difficult.


1 Answers

I had the similar question when I came across ngRx. In simple way and as per my understanding:

  1. Using ngRx you basically have a standard mechanism for State Management. We don't have to write extra piece of code that manages states as per the app requirement.

  2. Using ngRx plugins, we can actually time travel and check with what all state changes have the application gone through . That is a big thumbs up as it's not an easy task to implement all by ourselves.

  3. By following standard practices of reducers (pure functions), states (immutable) , selectors & stores basically we are trying to protect our app from any unpredictable changes. We also have effects to handle some scenarios.

  4. It provides a standard practice which can help entire community to stay on the same page. If everyone will write their own global services and achieve most of the things which ngRx provide, it can still be difficult for new comers. So, that's an important point as well.

  5. Refer Flux Architecture

  6. Not every app has to implement ngRx. Sometimes it can make your application messy.So think before you implement.
like image 62
Shashank Vivek Avatar answered Nov 09 '22 09:11

Shashank Vivek