Skip to content

Instantly share code, notes, and snippets.

@andrewgordstewart
Last active November 15, 2019 20:17
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 andrewgordstewart/2a237a1851b1d1e993b0522e79dea0c5 to your computer and use it in GitHub Desktop.
Save andrewgordstewart/2a237a1851b1d1e993b0522e79dea0c5 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const config = {
key: 'ledger-update',
initial: 'vote',
states: {
vote: {
on: {
'': [
{ target: 'waiting', cond: 'turnNumberCorrect', actions: 'vote' },
{ target: 'failure', cond: 'turnNumberIncorrect' }
]
}
},
waiting: {
on: {
'*': [
{ target: 'success', cond: 'consensusReached' },
{ target: 'failure', cond: 'dissent' }
]
}
},
success: { type: 'final' },
failure: { type: 'final' }
},
context: { channelID: '0xabc', currentTurnNumber: 7, goal: [] }
};
const guards = {
consensusReached: context => true,
// ensures that the latest supported
// state in the store has the correct
// turn number
turnNumberCorrect: context => true,
turnNumberIncorrect: context => false,
dissent: context => false
};
const customActions = {};
const machine = Machine(config, { guards, actions: customActions });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment