Skip to content

Instantly share code, notes, and snippets.

@thiagoadsix
Created August 21, 2020 17:54
Show Gist options
  • Save thiagoadsix/570eaddaba6e428a88ebffc024b92dd1 to your computer and use it in GitHub Desktop.
Save thiagoadsix/570eaddaba6e428a88ebffc024b92dd1 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: ['prepareQuestion'],
on: {
'': 'sendQuestion'
}
},
sendQuestion: {
entry: (_, event) => {
return event
},
on: {
'': 'waitingAnswer',
},
},
waitingAnswer: {
on: {
'front.message': 'validating',
},
},
validating: {
entry: ['validatingAnswer'],
on: {
'': 'saveContext'
}
},
saveContext: {
entry: assign((ctx, event) => {
ctx.data.marriageType = event.data
}),
on: {
'': 'success'
}
},
success: {
type: 'final'
}
}
}, {
actions: {
prepareQuestion: (ctx, event) => {
return {
msg: 'Qual tipo de casamento desejado?',
typeMarriage: {
civil: 'civil',
religious: 'religious',
},
ctx: console.log(ctx),
event: console.log(event)
}
},
validatingAnswer: (ctx, event) => {
return {
msg: 'Estamos avaliando sua resposta.'
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment