Skip to content

Instantly share code, notes, and snippets.

@davepies
Created September 22, 2020 11:16
Show Gist options
  • Save davepies/5c49d4a66ea82d970671abecce978252 to your computer and use it in GitHub Desktop.
Save davepies/5c49d4a66ea82d970671abecce978252 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const toggleMachine = Machine({
id: "siteProfileForm",
initial: "notSubmittable",
states: {
notSubmittable: {
on: { FORM_COMPLETE: "submittable" },
},
submittable: {
initial: "siteNotValidated",
states: {
siteNotValidated: {},
siteValidated: {},
},
on: {
SUBMIT: 'submitted',
FORM_INCOMPLETE: "notSubmittable",
TOGGLE_SITE_VALIDATION: "validateTargetSite",
},
},
submitted: {},
validateTargetSite: {
initial: "idle",
states: {
idle: {
on: {
START_VALIDATION: "validationInProgress",
},
},
validationInProgress: {
on: {
VALIDATION_SUCCESS: "#siteProfileForm.submittable.siteValidated",
VALIDATION_FAILURE: "validationFailure",
},
},
validationFailure: {
on: {
VALIDATION_RETRY: 'idle'
}
}
},
on: {
TOGGLE_SITE_VALIDATION: "#siteProfileForm.submittable",
},
},
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment