Semantic meaning of state.value
#1805
-
Hi! I'm trying to understand the semantic meaning of
I am generally curious to understand what |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Because keys identify the hierarchical path to a state node. This is the difference between representing a state like this: {
active: {
brightness: 'bright',
mode: 'light'
}
} Rather than this: [
'active',
'active.brightness',
'active.brightness.bright',
'active.mode',
'active.mode.light'
] Or with some unique IDs: // examples of IDs
[
'active',
'brightness',
'bright',
'mode',
'lightMode'
] It's more concise and useful to represent a state value (which represents the finite state) as its hierarchical representation, rather than just as a collection of IDs.
They can, but it's not as useful for the reason above. When you have an object (hierarchical representation), not only do you represent all of the state nodes in a compact manner, but you also represent their paths in the statechart. This is important for visualizing state nodes.
It's useful in // pseudocode
state.matches('#active') && state.matches('#lightMode') You can use the natural hierarchical representation: state.matches({ active: { mode: 'light' } });
For XState,
It is an XState "invention", and you're right, it's for practical purposes. The equivalent in SCXML is the internal {
"foo": {
"bar": "baz",
"bar": "quo" // can never happen!
}
} Similarly, by joining the path to each state node via its keys as its "default" ID (e.g., Hope that helps! |
Beta Was this translation helpful? Give feedback.
Because keys identify the hierarchical path to a state node. This is the difference between representing a state like this:
Rather than this:
Or with some unique IDs:
It's more concise and useful to represent a state value (which represents the finite state) as its hierarchical representation, rather than just as a collection of IDs.