Skip to content

Instantly share code, notes, and snippets.

@joaom182
Created November 12, 2021 00:49
Show Gist options
  • Save joaom182/f15498803a5e642e5c4bebb6cdfc8923 to your computer and use it in GitHub Desktop.
Save joaom182/f15498803a5e642e5c4bebb6cdfc8923 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 fetchMachine = Machine({
id: 'entityProfiles',
initial: 'profiles',
states: {
init: {
always: [{ target: 'profile-confirm-page', cond: 'isVisited' }, { target: 'profiles' }]
},
profiles: {
entry: ['clearSelectedEntityId'],
on: {
NEXT: {
target: 'profiles-edit',
actions: ['assignApplication']
},
EVENT_DATA: {
actions: ['assignApplication']
},
EVENT_CARD_DATA: {
actions: ['logger', 'assignCard']
}
}
},
'profiles-edit': {
entry: ['clearSelectedEntityId'],
on: {
NEXT: [
{
target: 'loop',
actions: ['assignAllFromData', 'assignEntityCards'],
cond: 'currentStateIsProfileDetails'
},
{
target: 'profile-confirm-page',
actions: ['assignApplication'],
cond: 'currentStateIsProfileConfirmPage'
}
],
EVENT_DATA: {
actions: ['assignApplication']
},
EVENT_CARD_DATA: {
actions: ['logger', 'assignCard']
}
}
},
loop: {
exit: ['clearCurrentEntityCards'],
on: {
NEXT: [
{
target: 'profiles-edit',
actions: ['assignAllFromData', 'assignEntityCards']
},
{
target: 'loop',
actions: ['assignApplication', 'assignCurrentEntityCards', 'incrementLoopIndex']
}
],
BACK: [
{
target: 'profiles-edit',
actions: ['assignApplication'],
cond: 'isFirstCard'
},
{
target: 'loop',
actions: ['assignApplication', 'assignCurrentEntityCards', 'decrementLoopIndex']
}
],
EVENT_DATA: {
actions: ['assignAllFromData']
},
EVENT_CARD_DATA: {
actions: ['logger', 'assignCard']
}
}
},
'profile-confirm-page': {
entry: ['clearSelectedEntityId'],
exit: ['clearCurrentEntityCards', 'assignIsVisited'],
on: {
NEXT: {
target: 'success',
actions: ['assignApplication']
},
BACK: {
target: 'profiles-edit',
actions: ['assignApplication']
},
EVENT_DATA: {
actions: ['assignApplication']
},
EVENT_CARD_DATA: {
actions: ['logger', 'assignCard']
}
}
},
success: {
exit: ['clearSelectedEntityId', 'clearCurrentEntityCards'],
type: 'final'
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment