Created
September 19, 2020 20:41
-
-
Save zaydek/e84f224087242dec53b99c53077b6aa6 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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