Skip to content

Instantly share code, notes, and snippets.

@robertpenner
Last active August 9, 2021 22:05
Show Gist options
  • Save robertpenner/09f9ed605cfba770df42c6b78cafe34a to your computer and use it in GitHub Desktop.
Save robertpenner/09f9ed605cfba770df42c6b78cafe34a to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const randomRange = (min, max) =>
min + Math.random() * (max - min);
const machine = Machine(
{
id: "Round as Individual Player",
type: "parallel",
states: {
"Player 1": {
id: "P1",
initial: "waiting",
states: {
waiting: {
on: { "START ROUND": "hole 1" },
},
"hole 1": {
initial: "playing",
states: {
playing: {
initial: "shot 1",
states: {
"shot 1": {
// after: {
// 1000: {
// actions: send("BALL HIT"),
// },
// },
on: { "BALL HIT": "shot 2" },
// on: { "BALL HIT": "shot N" },
},
"shot 2": {
on: { "BALL HIT": "shot N" },
},
"shot N": {},
},
on: {
// "BALL HIT": "playing",
"BALL HOLED": "hole complete",
},
},
"hole complete": {
on: {
"NEXT HOLE": "#P1.hole 2",
},
},
},
},
"hole 2": {
initial: "playing",
states: {
playing: {
initial: "shot 1",
states: {
"shot 1": {
on: { "BALL HIT": "shot 2" },
},
"shot 2": {
on: { "BALL HIT": "shot N" },
},
"shot N": {},
},
on: {
// "BALL HIT": "playing",
"BALL HOLED": "hole complete",
},
},
"hole complete": {
on: {
// 'NEXT HOLE': 'P1.hole 2',
},
},
},
},
},
}, // Player 1
score: {
initial: "up to date",
states: {
// empty: {},
"up to date": {
entry: send("SCORECARD CREATED"),
on: {
"BALL HOLED": "recalculating",
"SCORE CORRECTED": "recalculating",
},
},
recalculating: {
after: {
"calculation time": "up to date",
// "score calculation": {
// actions: send("SCORECARD CREATED"),
// },
},
},
},
},
}, // top-level states
// on: {
// "START ROUND": {},
// },
},
{
delays: {
"calculation time": 2000,
},
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment