Skip to content

Instantly share code, notes, and snippets.

@thiagoadsix
Created August 21, 2020 17:54
Show Gist options
  • Save thiagoadsix/6ee531930fad0c908ba9968dd5772a60 to your computer and use it in GitHub Desktop.
Save thiagoadsix/6ee531930fad0c908ba9968dd5772a60 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const typeMarriageMachine = Machine({
id: 'typeMarriageMachine',
initial: 'prepareQuestion',
context: {
data: {}
},
states: {
prepareQuestion: {
entry: 'entry1',
on: {
'': 'sendQuestion'
}
},
sendQuestion: {
entry: 'entry2',
on: {
'': 'waitingAnswer'
}
},
waitingAnswer: {
on: {
'front.message': 'validating'
}
},
validating: {
entry: 'entry3',
on: {
'validating.done': [
{
cond: () => false,
target: 'saveContext'
},
{
cond: () => true,
target: 'failure'
}
]
}
},
saveContext: {
entry: assign((ctx, event) => {
ctx.data.marriageType = event.data
}),
on: {
'': 'contextUpdate'
}
},
contextUpdate: {
on: {
'': {
actions: 'qcoisa',
target: 'success'
}
}
},
success: {
type: 'final'
},
failure: {
entry: 'entry4',
on: {
'': 'prepareQuestion'
}
}
}
}, {
actions: {
qcoisa: send((ctx, event) => ({type: 'context.update', data: ctx.data}))
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment