Search code examples
angularngrx

Using ngrx with Angular


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.


Solution

  • 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.