Skip to content

Instantly share code, notes, and snippets.

@anatomic
Last active January 19, 2021 22:04
Show Gist options
  • Save anatomic/080fec9a91fef4a31f043327657783e4 to your computer and use it in GitHub Desktop.
Save anatomic/080fec9a91fef4a31f043327657783e4 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
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