Closed josefbetancourt closed 5 years ago
Have you seen the semantics of <final>
states (as in SCXML)? https://xstate.js.org/docs/guides/final.html
We can model "all fields must be valid" by setting 'valid'
as the "final" state for each orthogonal node and listening for the done.state.*
event.
Suppose field1
looks like this (simplified):
const field1 = {
states: {
invalid: {
on: {
CHANGE: [
{ target: 'valid', cond: isValid },
{ target: 'invalid' }
]
}
},
valid: {
type: 'final'
}
}
};
Then the fields
parallel state can capture whether all fields are in their "final" states:
// ...
fields: {
type: 'parallel',
states: {
field1,
field2,
field3
},
onDone: 'formValid'
},
formValid: {
on: {
SUBMIT: // submittable
}
}
// ...
@davidkpiano That is truly awesome. I will update the blog post with this info. Thanks.
Not sure this is relevant to XState goals. The concept has not been evaluated yet.
Not much on the use of memory in Statechart. Only History, afaik, is in the standard. This blog post introduces the concept of states with memory attribute. These states with memory can then be connected to gates, similar to guards. So that statecharts "... handle more complex applications while still remaining a transition network at its core."
http://www.octodecillion.com/statechart-memory-gate/