Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function findAdjacencies(state: State) {
const { nextEvents } = state;
const stateHash = stateSerializer(state);
if (adjacency[stateHash]) {
return;
}
adjacency[stateHash] = {};
const potentialEvents = flatten(
nextEvents.map(nextEvent => events[nextEvent] || [])
).map(event => toEventObject(event));
for (const event of potentialEvents) {
let nextState: State;
try {
nextState = node.transition(state, event);
} catch (e) {
throw new Error(
`Unable to transition from state ${stateSerializer(
state
)} on event ${eventSerializer(event)}: ${e.message}`
);
}
if (
return stateNodeToSCXML(childStateNode);
});
const elements: XMLElement[] = [];
const { onEntry, onExit } = stateNode;
if (onEntry.length) {
elements.push(actionsToSCXML('onentry', onEntry));
}
if (onExit.length) {
elements.push(actionsToSCXML('onexit', onExit));
}
const transitionElements = flatten(
Object.keys(stateNode.on).map(event => {
const transitions = stateNode.on[event];
return transitions.map(transition => transitionToSCXML(transition));
})
);
elements.push(...transitionElements);
elements.push(...childStates);
if (stateNode.type === 'final' && stateNode.data) {
elements.push(doneDataToSCXML(stateNode.data));
}
return {
type: 'element',