Last active
April 9, 2021 17:28
-
-
Save conorhastings/1d2587cef368bab0ad409e5124314db4 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains 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 PIN = 1234; | |
const pinMachine = Machine({ | |
id: "wizard", | |
context: { | |
phone: "", | |
pin: "", | |
retries: 0 | |
}, | |
initial: "phone", | |
states: { | |
phone: { | |
on: { | |
NEXT: { | |
target: "pin", | |
actions: assign({ phone: (_, e) => e.value }) | |
} | |
} | |
}, | |
pin: { | |
on: { | |
NEXT: { | |
target: "checkPin", | |
actions: assign({ pin: (_, e) => e.value }), | |
} | |
} | |
}, | |
checkPin: { | |
invoke: { | |
id: "checkPin", | |
src: (context) => context.pin === PIN, | |
actions: assign({ pin: (context) => context.retires++ }), | |
cond: (context) => context.retries < 3, | |
onDone: "success", | |
onError: "failure" | |
} | |
}, | |
failure: { | |
on: { | |
RETRY: "checkPin", | |
} | |
}, | |
success: { | |
type: "final" | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment