Last active
February 11, 2020 22:55
-
-
Save theverything/08492f416d2b2f4a6543b48107b93c08 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 kegbotMachine = new Machine( | |
{ | |
id: "kegbot", | |
initial: "unauthenicated", | |
context: { | |
userID: null, | |
pourAmount: 0, | |
pourSelection: 0 | |
}, | |
states: { | |
unauthenicated: { | |
entry: ["reset"], | |
on: { | |
AUTH: "authenicated" | |
} | |
}, | |
authenicated: { | |
on: { | |
POUR: "pouring" | |
} | |
}, | |
pouring: { | |
entry: ["tick", "pourTimeout"], | |
exit: ["cancelPourTimeout"], | |
on: { | |
"": { | |
target: "finished", | |
cond: "pourLimit" | |
}, | |
POUR: "pouring", | |
FINISH: "finished" | |
} | |
}, | |
finished: { | |
on: { | |
UNAUTH: "unauthenicated" | |
} | |
} | |
} | |
}, | |
{ | |
actions: { | |
pourTimeout: actions.send("FINISH", { delay: 2000, id: "pourTimeout" }), | |
cancelPourTimeout: actions.cancel("pourTimeout"), | |
tick: assign({ pourAmount: ctx => ctx.pourAmount + 1 }), | |
reset: assign({ userID: null, pourAmount: 0, pourSelection: 0 }) | |
}, | |
guards: { | |
pourLimit: ctx => ctx.pourAmount >= 3 | |
} | |
} | |
); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment