What is State Management and why is it so important?
With great number of states, comes great responsibilities.
If you've ever been into game development, you will find that animations states are really awful thing to deal with, let alone debug it, so we turned into State Machine Pattern for help, and boy it did really help us control the mess!
but what mess am I talking about?
For example, let's say we have a delivery package tracking application like this
So we have a system where orders have their own states, I'll try to be simple since we are not trying to actually build the app here, just a quick overview...
- Order Sent
- Order Regulated
- Order Accepted
- Order In Manufacturing
- Order Sent to Warehouse
- Connecting with Delivery Service
- USP Accepted
- USP Sent Courier
- USP Picked Package
- USP Delivering
- USP Courier Is Close
- USP Sent Package
- USP Courier Confirmed
- Customer Confirmed
- Customer Reviewed Package
- Moderator Accepted Review
For each State in here, there may happen a failure issue, and there may be intertwined states, and there may be some recover action to be taken to recover from failure state, and there may be a pending action on 2 or more states, so you basically are trying to this...
Also, this state handling may happen on both client and backend application, so if you are not using something to organize this... you may end up with some big pile of code like this
So, Key points to learn from this post, If you find yourself in a situation where you have too many states to handle, check State Machines and learn when and how to implement one.
Where to go from here?
Ok, now we're ready to go deeper into Redux and why it's a good fit for SwiftUI
We will be discussing how Redux + SwiftUI + Combine can make a great Team 7) 🥷