Skip to content

Instantly share code, notes, and snippets.

@zaydek
Created September 19, 2020 20:41
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 zaydek/e84f224087242dec53b99c53077b6aa6 to your computer and use it in GitHub Desktop.
Save zaydek/e84f224087242dec53b99c53077b6aa6 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const MAX_ALLOWABLE_ATTEMPTS = 3
const userLoginMachine = Machine({
id: "userLogin",
initial: "loginScreen",
context: {
authError: "",
attemptCount: 0,
},
states: {
loginScreen: {
on: {
SUBMIT_CREDENTIALS: "authentication",
}
},
authentication: {
invoke: {
id: "authenticationHandler",
src: (ctx, e) => new Promise((resolve, reject) => {
setTimeout(() => {
reject()
}, 1e3)
}),
onDone: {
target: "userWelcomeScreen",
},
onError: {
target: "loginScreen",
actions: assign({
authError: "We couldn’t authenticate you with those credentials. Please try again",
attemptCount: (ctx, e) => ctx.attemptCount + 1,
}),
},
}
},
userBlockedScreen: {
// ...
},
userWelcomeScreen: {
// ...
},
},
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment