I am working on rewriting a highly complex form at my company that has become a main source of headaches, bugs, and frustration for both developers and users.
It is a highly dynamic form with a complex schema that requires server-side interaction for validation on blur of any field. The server response can return errors, overwrite user values, and create / remove new fields if needed. Each individual field needs to be able to display these various states (errors, notifications of bounding value, etc). It's been a while since I've used xstate, particularly xstate 5 and the actor model, so I wanted to make sure I was thinking about modeling this correctly.
We will have a top level machine that will be responsible for receiving our domain object, initializing the form and holding references to the field-level child actors, spawning a promise actor when we make server requests, and correctly passing down events to the child actors on server response.
Each individual field will be a child actor that initializes with a value, and is responsible for passing messages to the parent machine when the user changes the field and receiving messages from the parent in response to a server response. The individual field will be responsible for displaying error / notification states when it receives a new value event from its parent.
In addition, there needs to be both field level undo-redo and top-level (recursive). Will history states be the main thing to use here to achieve that?
Does this all sounds reasonable? I know it's slightly vague requirements, but just making sure this modeling makes sense before I dive in too deeply.