Skip to content

Instantly share code, notes, and snippets.

@joaom182
Created November 12, 2021 01:24
Show Gist options
  • Save joaom182/5a8fc207b001a3126f3b1adde87915e0 to your computer and use it in GitHub Desktop.
Save joaom182/5a8fc207b001a3126f3b1adde87915e0 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', 'assignCurrentEntityCardsFromStage3'],
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'],
cond: 'isLastCard'
},
{
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