angularstorengrx-storestate-managementangular-state-managmement

Why do we need ngrx/store even we can use services and localStorages?


In angular, we are maintaining the state using ngrx/store. My doubt is we can handle all of the kinds of stuff even with the services. What are the advantages of handling the ngrx/store package? Kindly inform me.Thanks in advance.


Solution

  • My take, main benefits are:

    1. Simplifies state management
    2. Follows CQRS pattern which separates commands from queries,and makes asynchronous event programming much more stable, scalable, and predictable.
    3. Allows you to reuse state changing logic (in the form of reducers), which greatly reduces the amount of boilerplate code to perform repetitive tasks, such as CRUD operations.
    4. Easy to move to redux, once you realize there are similarities between OOP and FP/redux

    You may have to experience the pain of maintaining an app with over 100 angular services, triggering events in a spaghetti-like cascade, changing state in a variety of different ways in a non deterministic manner, with complex components subscribing to those events, and trying your best to manage the complexity while encountering a number of obscure race conditions in order to truly appreciate the advantages of Ngrx.

    Put another way, if you appreciate the complexities of FRP and asynchronous programming and understand how the OOP is beneficial, then you should also understand (with time) how Ngrx will help you to simplify and manage the complexity in a way that’s maintainable