Last active
January 19, 2021 22:04
-
-
Save anatomic/080fec9a91fef4a31f043327657783e4 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
const formMachine = Machine({ | |
id: "formMachine", | |
initial: "editing", | |
context: { | |
questions: [], | |
name: "" | |
}, | |
states: { | |
editing: { | |
initial: "addOnly", | |
states: { | |
addOnly: {}, | |
canDelete: { | |
on: { | |
deleteQuestion: [ | |
{ | |
target: "addOnly", | |
actions: "deleteQuestion", | |
cond: "isPenultimate" | |
}, | |
{ | |
actions: "deleteQuestion" | |
} | |
] | |
}, | |
} | |
}, | |
on: { | |
addResponse: { | |
target: ".canDelete", | |
actions: "addQuestion" | |
}, | |
submit: { | |
target: "submitting" | |
} | |
} | |
}, | |
submitting: { | |
invoke: { | |
src: "submitForm", | |
onDone: "created", | |
onError: "failed" | |
} | |
}, | |
created: { | |
type: "final", | |
}, | |
failed: { | |
} | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment