Last active
March 15, 2020 16:52
-
-
Save taktran/fb35d31c54f77ec1107bc59575f3c84a to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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