Created
November 15, 2019 00:14
-
-
Save andrewgordstewart/6fbfa02b5186466de8c5d6bd250127e4 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains 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 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