Last active
May 21, 2021 15:33
-
-
Save keithernet/6230cb09578ef8c0e3eae84d36ec7a0d to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function fetchSecondOptions(someId){ | |
return new Promise(resolve => { | |
setTimeout(() => resolve([]), 300); | |
}); | |
} | |
function fetchThirdOptions(someId){ | |
return new Promise(resolve => { | |
setTimeout(() => resolve([]), 500); | |
}); | |
} | |
const cascadingSelectControlsMachine = Machine( | |
{ | |
id: "cascadingSelectControls", | |
initial: "awaitingFirstSelection", | |
states: { | |
awaitingFirstSelection: { | |
on: { | |
FIRST_SELECTED: "firstSelected" | |
}, | |
}, | |
firstSelected: { | |
initial: "loadingSecondOptions", | |
on: { | |
FIRST_SELECTED: ".loadingSecondOptions" | |
}, | |
states: { | |
loadingSecondOptions: { | |
invoke: { | |
src: (context, event) => fetchSecondOptions(event.data), | |
onDone: { | |
target: 'awaitingSecondSelection' | |
} | |
} | |
}, | |
awaitingSecondSelection: { | |
on: { | |
SECOND_SELECTED: "loadingThirdOptions" | |
} | |
}, | |
loadingThirdOptions: { | |
invoke: { | |
src: (context, event) => fetchThirdOptions(event.data), | |
onDone: { | |
target: 'secondSelected' | |
} | |
} | |
}, | |
secondSelected: { | |
initial: "awaitingThirdSelection", | |
on: { | |
SECOND_SELECTED: "loadingThirdOptions" | |
}, | |
states: { | |
awaitingThirdSelection: { | |
on: { | |
THIRD_SELECTED: "thirdSelected" | |
} | |
}, | |
thirdSelected: {} | |
} | |
} | |
} | |
} | |
}, | |
}, | |
{}, | |
); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment