Skip to content

Instantly share code, notes, and snippets.

@epan
Last active June 18, 2020 17:24
Show Gist options
  • Save epan/8786d11d137094e8c09dda078a8874e1 to your computer and use it in GitHub Desktop.
Save epan/8786d11d137094e8c09dda078a8874e1 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// V1.1 basic with new vs existing address flow states
const addressManagerMachine = Machine({
id: 'addressManager',
initial: 'closed',
states: {
closed: {
on: {
CLICK: 'addressList'
}
},
addressList: {
initial: 'list',
states: {
list: {
on: {
SELECT: '#addressManager.setAddressAsDefault',
EDIT: '#addressManager.editExistingAddress',
SEARCH: 'searchResults',
}
},
searchResults: {
on: {
SELECT: '#addressManager.editNewAddress',
}
}
},
},
editExistingAddress: {
on: {
CANCEL: 'addressList',
SAVE: 'addressList',
ADJUST_PIN: 'changeExistingPinLocation'
}
},
editNewAddress: {
on: {
CANCEL: 'addressList',
SAVE: 'setAddressAsDefault',
ADJUST_PIN: 'changeNewPinLocation'
}
},
setAddressAsDefault: {
on: {
SUCCESS: 'closed',
FAIL: 'addressList'
}
},
changeExistingPinLocation: {
on: {
CANCEL: 'editExistingAddress',
SAVE: 'editExistingAddress'
}
},
changeNewPinLocation: {
on: {
CANCEL: 'editNewAddress',
SAVE: 'editNewAddress'
}
},
loading: {},
},
on: {
CLOSE: '.closed'
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment