Created
March 25, 2021 06:23
-
-
Save Bogidon/59aea31a503ef41adfb55cbd8f267ca8 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains hidden or 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
/************* | |
Fixed | |
*************/ | |
const STATES = Object.fromEntries(["animalKingdom", "dogOrCat", "petAge", "enrolledInPuppySchool", "recommendedProduct"].map(x => [x, x])) | |
const GUARDS = Object.fromEntries(["isMammal", "isFish", "isDog", "isCat", "petNameValid"].map(x => [x, x])) | |
const TRANSITIONS = Object.fromEntries(["continue", "error"].map(x => [x, x])) | |
// FULLY SERIALIZED | |
// { | |
// // Question 1: dog or cat? | |
// "dogOrCat": { | |
// "on": { | |
// "continue": "petAge" | |
// }, | |
// }, | |
// // Question 2: pet age | |
// "petAge": { | |
// "on": { | |
// "continue": "recommendedProduct" | |
// }, | |
// }, | |
// // Question 3: recommended product | |
// "recommendedProduct": { | |
// "type": "final" | |
// } | |
// }; | |
// JS-keys | |
const states = { | |
// Question 1: dog or cat? | |
[STATES.dogOrCat]: { | |
on: { | |
[TRANSITIONS.continue]: STATES.petAge | |
}, | |
}, | |
// Question 2: pet age | |
[STATES.petAge]: { | |
on: { | |
[TRANSITIONS.continue]: STATES.recommendedProduct | |
}, | |
}, | |
// Question 3: recommended product | |
[STATES.recommendedProduct]: { | |
type: "final" | |
} | |
} | |
Machine({ | |
id: 'petFlow', | |
initial: "dogOrCat", | |
states | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment