Reputation: 961
Yes I know that it's already asked in several variations but I'm unsatisfied by all of the answers.
All the answers points about features of the redux but non of them is essential:
Can you give me please ONE essential/important reason for using redux and not angular services?
Upvotes: 5
Views: 282
Reputation: 704
I think the main criterion is the complexity of your client logic. Is it complex enough to make services too convoluted? Do you have any complex dependencies between different parts of state data that are required to calculate some UI constraints?
At some point you might find yourself implementing something that resembles the functionality of the existing sate mgmt libraries out there.
For example, you might have some sort of a wizard for a complex process of setting up some monitoring that churns through incoming data with lots of different options.
There may be dependencies between steps that steps themselves needn't know about in details (so that you can't go to step 2 until something in step 1 is done, or step 3 might depend on the selected set of flags in step 2 and so on). You might want to keep all your state creation and update logic in one place (ability to trace the path you code executes is also a good thing to remember about).
This is where you can try to implement your state as a NGXS state, for example. Define human-readable actions, keep your update logic in a separate class specifically designed for it, provide observables from your state to components. You don't have to duplicate logic that is responsible for sending update signals (e.g. recalculate step 2 completion flag on a field change and send it through the corresponding subject).
It might also seem too hard to understand at first but on ther other hand, next wizard will feel less hard to do, and you don't have to do it for all the state you have in your app.
Upvotes: 3