What is State Management and why is it so important?

What is State Management and why is it so important?

With great number of states, comes great responsibilities.

ยท

2 min read

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

Screen Shot 2021-06-25 at 5.21.11 PM.png

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

  1. Order Sent
  2. Order Regulated
  3. Order Accepted
  4. Order In Manufacturing
  5. Order Sent to Warehouse
  6. Connecting with Delivery Service
  7. USP Accepted
  8. USP Sent Courier
  9. USP Picked Package
  10. USP Delivering
  11. USP Courier Is Close
  12. USP Sent Package
  13. USP Courier Confirmed
  14. Customer Confirmed
  15. Customer Reviewed Package
  16. 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...

image.png

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

Screen Shot 2021-06-25 at 5.28.26 PM.png

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) ๐Ÿฅท

Reading Material

  1. State Machine Pattern
ย