Skip to content

Instantly share code, notes, and snippets.

@zaydek

zaydek/machine.js

Created Sep 19, 2020
Embed
What would you like to do?
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
You can’t perform that action at this time.