Skip to content

Instantly share code, notes, and snippets.

@bholmesdev
Last active August 17, 2020 15:34
Show Gist options
  • Save bholmesdev/da1509bc3111200ab2467882180554aa to your computer and use it in GitHub Desktop.
Save bholmesdev/da1509bc3111200ab2467882180554aa to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
const configureMachine = Machine({
id: 'configure',
initial: 'idle',
context: {
},
states: {
idle: {
type: 'parallel',
states: {
form: {
initial: 'isIncomplete',
states: {
isComplete: {
on: {
SUBMIT: '#submitting',
ERRORS_FOUND: 'isIncomplete'
}
},
isIncomplete: {
on: {
SUBMIT: {
actions: ['focusErrors']
},
ERRORS_CLEARED: 'isComplete'
}
}
}
},
rockLobster: {
initial: 'isOff',
states: {
isOn: {
on: {
TOGGLE_ROCK_LOBSTER: {
target: 'isOff',
actions: ['scrollUp', 'removeFadeEffect']
}
}
},
isOff: {
on: {
TOGGLE_ROCK_LOBSTER: {
target: 'isOn',
actions: ['scrollDown', 'addFadeEffect']
}
}
}
}
}
},
},
submitting: {
id: 'submitting',
invoke: {
src: 'addToCart',
onDone: 'submitted',
onError: 'idle.form.isComplete'
}
},
submitted: {
type: 'final'
}
}
},
{
rockLobsterOn: (context) => context.rockLobsterToggled,
rockLobsterOff: (context) => !context.rockLobsterToggled
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment