Created
January 25, 2021 22:51
-
-
Save BrianCortes/f19b4e629d8f9a243dbd68530fec1487 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
// Available variables: | |
// - Machine | |
// - interpret | |
// - assign | |
// - send | |
// - sendParent | |
// - spawn | |
// - raise | |
// - actions | |
// - XState (all XState exports) | |
const fetchUser = () => { | |
return new Promise().resolve(); | |
} | |
const fetchMachine = Machine({ | |
id: 'fetch', | |
initial: 'idle', | |
context: { | |
form: { | |
email: '', | |
password: '' | |
} | |
}, | |
states: { | |
idle: { | |
on: { | |
SUBMIT: 'loading', | |
GO_BACK: { | |
target: '', | |
actions: ['goBack'] | |
}, | |
GO_ACCOUNT: { | |
target: '', | |
actions: ['goAccount'] | |
} | |
} | |
}, | |
loading: { | |
invoke: { | |
id: 'loginUser', | |
src: (context, event) => fetchUser(context.userId), | |
onDone: { | |
target: 'success_login', | |
actions: ['saveDataUser'] | |
}, | |
onError: { | |
target: 'failure_login', | |
actions: ['showError'] | |
} | |
} | |
}, | |
success_login: {}, | |
failure_login: { | |
on: { | |
RETRY: 'loading' | |
} | |
} | |
} | |
}, | |
{ | |
actions: { | |
goBack: () => { | |
console.log('go back'); | |
}, | |
goAccount: () => { | |
console.log('go accont'); | |
}, | |
saveDataUser: () => { | |
console.log('saveDataUser'); | |
}, | |
showError: () => { | |
console.log('showError'); | |
} | |
} | |
} | |
); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment