Skip to content

Instantly share code, notes, and snippets.

@taktran
Last active March 15, 2020 16:52
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 taktran/fb35d31c54f77ec1107bc59575f3c84a to your computer and use it in GitHub Desktop.
Save taktran/fb35d31c54f77ec1107bc59575f3c84a to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const isWinner = ({ score, totalScore }) => score >= totalScore;
const playMachine = Machine({
id: "play",
initial: "playing",
context: {
score: 0,
totalScore: 10
},
states: {
playing: {
entry: ["onRestart", assign({ score: 0 })],
on: {
UPDATE_SCORE: {
actions: assign({
score: (_, payload) => {
const { score } = payload;
return score;
}
})
},
"": {
target: "win",
cond: isWinner
}
}
},
win: {
on: { RESTART: "playing" }
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment