Skip to content

Instantly share code, notes, and snippets.

@bmeck
Last active February 20, 2020 16:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bmeck/af21e01be0f45297cf0ddfd73cc1c235 to your computer and use it in GitHub Desktop.
Save bmeck/af21e01be0f45297cf0ddfd73cc1c235 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const loop = Machine({
context: { x: 3 },
initial: 'while (x > 0)',
states: {
"while (x > 0)": {
on: {
EVAL: [
{
target: "x--",
cond(ctx, evt) {
return ctx.x > 0;
}
},
{ target: "done",
cond(ctx, evt) {
return ctx.x > 0 !== true;
} }
]
}
},
"x--": {
on: {
EVAL: {
target: "while (x > 0)",
actions(ctx, event) {
ctx.x--;
}
}
}
},
done: { type: "final" }
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment