Advice on getting valid transition targets for node #1386
-
I'm working on xstate-codegen, and I've been trying to think of a way to get all the valid transition targets from a node. I'd like to get them as strings, with the delimiter, so that I can use them for type checking. Here's what I need to get:
I am getting there, but I wondered if you have any shortcuts/utils I can use? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
Do you mean all the targets of all the transitions from a state node? function getAllTransitionTargets(stateNode) {
return flatten(stateNode.transitions.map(t => {
return t.target || [];
}));
} That should do it. You can dedupe using This is after the machine does the "processing" of the config object. |
Beta Was this translation helpful? Give feedback.
Do you mean all the targets of all the transitions from a state node?
That should do it. You can dedupe using
Set()
and recursively get all the transition targets of the sibling nodes themselves (Object.values(stateNode.states)
).This is after the machine does the "processing" of the config object.