Skip to content

Instantly share code, notes, and snippets.

@thorgas
Created April 21, 2021 19:44
Show Gist options
  • Select an option

  • Save thorgas/61368b468f7cc7dc2f93e85a844b6cf1 to your computer and use it in GitHub Desktop.

Select an option

Save thorgas/61368b468f7cc7dc2f93e85a844b6cf1 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 CreateAccountStates = {
loadingPrerequisites : 'loadingPrerequisites',
createAccount : 'createAccount',
addFirstPage : 'addFirstPage',
addSecondPage : 'addSecondPage',
loading : 'loading',
error : 'error',
finished : 'finished',
}
const CreateAccountEvents = {
DONE : 'DONE',
SUBMIT : 'SUBMIT',
LOADING : 'LOADING',
CREATE_ACCOUNT : 'CREATE_ACCOUNT',
ADD_FIRST_PAGE : 'ADD_FIRST_PAGE',
ERROR : 'ERROR',
}
const fetchMachine = Machine({
id: 'createMangoAccount',
initial: CreateAccountStates.loadingPrerequisites,
context: {
error: false,
errorMessage: '',
profile: null,
},
states: {
loadingPrerequisites: {
on: {
DONE: {
target: 'createAccount',
actions: assign({ profile: (_, profile) => profile }),
},
},
},
createAccount: {
on: {
SUBMIT: {
target: 'loading',
// TODO remap birthday
actions: assign({ profile: (_, profile) => profile }),
},
},
},
addFirstPage: {
on: {
DONE: 'addSecondPage',
},
},
addSecondPage: {
on: { DONE: 'finished' },
},
loading: {
on: { CREATE_ACCOUNT: 'createAccount', ADD_FIRST_PAGE: 'addFirstPage', ERROR: 'error' },
},
error: {
type: 'final',
},
finished: {
type: 'final',
},
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment