Skip to content

Instantly share code, notes, and snippets.

@eddiewang
Last active February 29, 2020 19:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eddiewang/19c391a45873697fc0df57d131040564 to your computer and use it in GitHub Desktop.
Save eddiewang/19c391a45873697fc0df57d131040564 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 authMachine = Machine({
id: 'auth',
initial: 'idle',
context: {
username: '',
password: ''
},
states: {
idle: {
type: 'parallel',
on: {
INPUT: {
actions: 'cacheInput',
target: 'idle.inputs.noError'
},
SUBMIT: [
{
cond: 'isNoUsername',
target: 'idle.inputs.error.empty'
},
{
target: 'loading'
}
],
},
states: {
inputs: {
initial: 'noError',
noError: {},
error: {
initial: 'empty',
states: {
empty: {}
}
}
}
}
},
loading: {
on: {
RESOLVE: 'success',
REJECT: 'failure'
}
},
success: {
type: 'final'
},
failure: {
on: {
RETRY: {
target: 'loading',
actions: assign({
retries: (context, event) => context.retries + 1
})
}
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment