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.
CodePudding user response:
I think you should read those two articles about Ngrx store it might help you understand better:
- https://blog.angular-university.io/angular-ngrx-store-and-effects-crash-course/
- https://blog.angular-university.io/angular-2-redux-ngrx-rxjs/
Thanks!
CodePudding user response:
My take, main benefits are:
- Simplifies state management
- Follows CQRS pattern which separates commands from queries,and makes asynchronous event programming much more stable, scalable, and predictable.
- 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.
- 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