Skip to content

Instantly share code, notes, and snippets.

@davidkpiano
Created December 14, 2019 19:24
Show Gist options
  • Save davidkpiano/1efc412a056d58803e34d918923c6e7c to your computer and use it in GitHub Desktop.
Save davidkpiano/1efc412a056d58803e34d918923c6e7c to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const everyoneApproved = ctx => ctx.approvals >= 2;
const machine = Machine({
id: 'approval',
initial: 'requesting',
context: {
approvals: 0
},
states: {
requesting: {
entry: assign({ approvals: 0 }),
on: {
'': {
target: 'success',
cond: everyoneApproved
},
APPROVE: {
actions: assign({
approvals: ctx => ctx.approvals + 1
})
},
REJECT: 'failure'
}
},
success: {
type: 'final'
},
failure: {
on: {
RETRY: 'requesting'
}
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment