Skip to content

Instantly share code, notes, and snippets.

@theverything
Last active February 11, 2020 22:55
Show Gist options
  • Save theverything/08492f416d2b2f4a6543b48107b93c08 to your computer and use it in GitHub Desktop.
Save theverything/08492f416d2b2f4a6543b48107b93c08 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
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