Skip to content

Instantly share code, notes, and snippets.

@mathewtrivett
Created March 5, 2021 11:21
Show Gist options
  • Save mathewtrivett/7622d98fa19cd573e972402fe3389990 to your computer and use it in GitHub Desktop.
Save mathewtrivett/7622d98fa19cd573e972402fe3389990 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 = Machine({
id: 'createAccount',
initial: 'init',
context: {
retries: 0
},
states: {
init: {
on: {
NEXT: 'email'
}
},
email: {
on: {
NEXT: {
target: 'mobile'
}
}
},
mobile: {
on: {
SEND_OTP: {
target: 'sendingOTP',
}
}
},
sendingOTP: {
initial: 'sending',
states: {
sending: {
on: {
RESOLVE: {
target: 'success'
},
REJECT: {
target: 'failure'
}
}
},
success: {},
failure: {}
},
},
failure: {
on: {
RETRY: {
target: 'init',
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