Skip to content

Code review for xstate code for an upcoming YouTube video #1375

Answered by davidkpiano
jherr asked this question in General
Discussion options

You must be logged in to vote

For reference, here's the code:

updateResponse: {
    actions: ["updateResponse", send("checkResponses")],
},
checkResponses: {
    target: "VOTE",
    cond: "everyoneResponded",
},

You can also do this:

updateResponse: [
  { target: 'VOTE', cond: 'everyoneResponded', actions: 'updateResponse' },
  { actions: 'updateResponse' }
]

Which reads like:

Go to vote if everyone responded, and update the response. Otherwise, just update the response.

You might feel uneasy about the repetition in the 'updateResponse' action, but it's more clear/explicit than:

Always update the response and go to vote if everyone responded.

You can always create a helper function to remove the repetition:

function 

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@jherr
Comment options

@davidkpiano
Comment options

@jherr
Comment options

Answer selected by jherr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants