Using ngrx with Angular

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.

In now days subscriber patter is more powerful and robust. You will see the success of redux in React and Angular with ngrx. They have proper mechanism to handle data flow and proper way to manage code. You will not need to write verbose code to manage back and forth data flow using service, they provide all predefined cooked function and peace of code to use.

Use ngrx with effect and Entity Adapter to make things more clear.

But it depends on your application, sometimes it unnecessary add complexity into applications. But if you are not able to manage state on client side then you should go for that.


I have written a library to save you from the hell of ngrx. It is called RxCache.

Take a look at RxCache, it gives you the push based data flow of observable and frees you from the complete insanity of ngrx.

https://github.com/adriandavidbrand/ngx-rxcache

Tags:

Angular

Ngrx