Skip to content

Instantly share code, notes, and snippets.

@andrewgordstewart
Created November 15, 2019 00:14
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/6fbfa02b5186466de8c5d6bd250127e4 to your computer and use it in GitHub Desktop.
Save andrewgordstewart/6fbfa02b5186466de8c5d6bd250127e4 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const config = {
key: 'declarative-ledger-update',
initial: 'start',
states: {
start: {
entry: 'voteForGoal',
on: {
CHANNEL_UPDATED: [
{ target: 'start', cond: 'shouldVote', actions: 'voteForGoal' },
{ target: 'success', cond: 'consensusReached' },
{ target: 'failure', cond: 'maxTurnExceeded' }
]
}
},
success: { type: 'final' },
failure: { type: 'final' }
},
context: { channelID: '0xabc', maxTurnNumber: 10, goal: ['Goal'] }
};
const guards = {
maxTurnExceeded: function(c, e) {
return e.turnNumber > c.maxTurnNumber;
},
shouldVote: function(c, e) {
return !guards.maxTurnExceeded(c, e);
}
};
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