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.
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.
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? 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.
I had the similar question when I came across ngRx
. In simple way and as per my understanding:
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.
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.
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.
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.
Refer Flux Architecture
ngRx
. Sometimes it can make your application messy.So think before you implement.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