Created
August 21, 2020 17:54
-
-
Save thiagoadsix/570eaddaba6e428a88ebffc024b92dd1 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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