Skip to content

Instantly share code, notes, and snippets.

@tiagonevestia
Created October 10, 2019 14:31
Show Gist options
  • Save tiagonevestia/31fcb7fabf3987a7e6f2ac549fe32f0d to your computer and use it in GitHub Desktop.
Save tiagonevestia/31fcb7fabf3987a7e6f2ac549fe32f0d to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const fetchMachine = Machine({
id: 'post-screen',
initial: 'ready',
context: {
text: '',
},
states: {
ready: {
type: 'paralell',
on: {
INPUT_TEXT: {
actions: 'cacheText',
target: 'ready.text.noError'
},
SUBMIT: [
{
target: 'ready.text.error.empty',
cond: 'isNoText',
},
{
target: 'waitingResponse',
},
],
},
states: {
text: {
initial: 'error',
states: {
noError: {},
error: {
initial: 'empty',
states: {
empty: {},
},
onEntry: 'focusTextInput',
},
},
}
}
},
waitingResponse: {
on: {
CANCEL: 'ready',
},
invoke: {
src: 'requestPostCreate',
},
onDone: {
actions: 'onSuccess',
},
onError: [
{
cond: 'isInternalServerErr',
target: 'ready.authService.error.internal',
},
// {
// cond: "isIncorrectPassword",
// target: "ready.password.error.incorrect"
// },
// {
// cond: "isNoResponse",
// target: "ready.authService.error.communication"
// },
// {
// cond: "isInternalServerErr",
// target: "ready.authService.error.internal"
// }
],
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment