Skip to content

Instantly share code, notes, and snippets.

@BrianCortes
Last active February 3, 2021 21:11
Show Gist options
  • Save BrianCortes/49d2daa6ff14edbf910f56e3af8ad04f to your computer and use it in GitHub Desktop.
Save BrianCortes/49d2daa6ff14edbf910f56e3af8ad04f to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// 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