Skip to content

Instantly share code, notes, and snippets.

@apnerve
Created June 25, 2021 14:14
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 apnerve/13ee08c01ff1ad4b08abb980864dc7b8 to your computer and use it in GitHub Desktop.
Save apnerve/13ee08c01ff1ad4b08abb980864dc7b8 to your computer and use it in GitHub Desktop.
There's a hole in my bucket song as a state chart
const bucketMachine = Machine({
id: 'fetch',
initial: "There's a hole in my bucket",
states: {
"There's a hole in my bucket": {
on: {
THEN_FIX_IT: 'With what should I fix it?'
}
},
'With what should I fix it?': {
on: {
WITH_A_STRAW: 'But the straw is too long'
}
},
'But the straw is too long': {
on: {
THEN_CUT_IT: "With what shall I cut it?"
}
},
"With what shall I cut it?": {
on: {
WITH_AN_AXE: "But the axe is too dull"
}
},
"But the axe is too dull": {
on: {
THEN_SHARPEN_IT: "With what should I sharpen it?"
}
},
"With what should I sharpen it?": {
on: {
WITH_A_STONE: "But the stone is too dry"
}
},
"But the stone is too dry": {
on: {
THEN_WET_IT: "With what should I wet it?"
}
},
"With what should I wet it?": {
on: {
WITH_WATER: "But how shall I get it?"
}
},
"But how shall I get it?": {
on: {
IN_THE_BUCKET: "There's a hole in my bucket"
}
}
}
});
@apnerve
Copy link
Author

apnerve commented Jun 25, 2021

Paste it in https://xstate.js.org/viz/ and click "update" to see the flow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment