Skip to content

Instantly share code, notes, and snippets.

@epan
Created June 12, 2020 06:32
Show Gist options
  • Save epan/8d36362c6b2997f94c64f26b060eb772 to your computer and use it in GitHub Desktop.
Save epan/8d36362c6b2997f94c64f26b060eb772 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 addressManagerMachine = Machine({
id: 'addressManager',
context: { prompts: [] },
initial: 'closed',
states: {
closed: {
on: {
CLICK: 'addressList'
}
},
addressList: {
initial: 'list',
states: {
list: {
on: {
// GET PromptList
SELECT: [
{
target: '#addressManager.consumerPrompt',
cond: 'hasPrompts'
},
{
target: '#addressManager.closed',
}
],
// GET PromptList
EDIT: [
{
target: '#addressManager.consumerPrompt',
cond: 'hasPrompts'
},
{
target: '#addressManager.editAddressForm',
}
],
SEARCH: 'searchResults',
}
},
searchResults: {
on: {
// GET PromptList
SELECT: [
{
target: '#addressManager.consumerPrompt',
cond: 'hasPrompts'
},
{
target: '#addressManager.editAddressForm',
}
],
}
}
},
},
editAddressForm: {
on: {
CANCEL: 'addressList',
SAVE: 'addressList',
ADJUST_PIN: 'changePinLocationForm'
}
},
changePinLocationForm: {
on: {
CANCEL: 'editAddressForm',
SAVE: 'editAddressForm'
}
},
consumerPrompt: {
on: {
AGREE: 'changePinLocationForm',
// TODO: FIX REJECT
REJECT: 'closed'
}
},
loading: {},
},
on: {
CLOSE: '.closed'
}
}, {
guards: {
hasPrompts: context => context.prompts.length > 0
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment