Last active
February 3, 2021 21:11
-
-
Save BrianCortes/49d2daa6ff14edbf910f56e3af8ad04f 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 createAccount = () => { | |
return new Promise((resolved) => { | |
setTimeout(() => { resolved() }, 1000) | |
}) | |
} | |
const createAccountMachine = Machine({ | |
id: 'createAccount', | |
initial: 'idle', | |
context: { | |
email: '', | |
firstName: '', | |
lastName: '', | |
password: '' | |
}, | |
states: { | |
idle: { | |
on: { | |
GO_BACK: { | |
target: '', | |
actions: ['goBack'] | |
}, | |
SEND_FORM: { | |
target: 'loading' | |
} | |
} | |
}, | |
loading: { | |
invoke: { | |
src: createAccount, | |
onDone: { | |
target: 'success' | |
}, | |
onError: { | |
target: 'failure' | |
} | |
} | |
}, | |
success: { | |
type: 'final' | |
}, | |
failure: { | |
on: { | |
RETRY: { | |
target: 'idle', | |
} | |
} | |
} | |
} | |
}, | |
{ | |
actions: { | |
goBack: () => { console.log('go back') } | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment