Last active
April 1, 2020 20:27
-
-
Save andrewgordstewart/ab440fae9ee054d330459ebad0a98e92 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 guards = { | |
channelOpen: {name: 'channelOpen', predicate: () => true, type: 'xstate.guard'}, | |
channelClosing: {name: 'channelClosing', predicate: () => true, type: 'xstate.guard'}, | |
channelClosed: {name: 'channelClosed', predicate: () => true, type: 'xstate.guard'}, | |
isDirectFunding: {name: 'isDirectFunding', predicate: () => true, type: 'xstate.guard'}, | |
amCreator: {name: 'amCreator', predicate: () => true, type: 'xstate.guard'}, | |
amJoiner: {name: 'amJoiner', predicate: () => true, type: 'xstate.guard'} | |
}; | |
const customActions = {}; | |
const config = { | |
id: 'application-workflow', | |
initial: 'branchingOnFundingStrategy', | |
on: {CHANNEL_UPDATED: {actions: ['sendChannelUpdatedNotification']}}, | |
states: { | |
branchingOnFundingStrategy: { | |
on: { | |
'': [ | |
{ | |
target: 'confirmingWithUser', | |
cond: {name: 'isDirectFunding', predicate: () => true, type: 'xstate.guard'} | |
}, | |
{target: 'checkingBudget'} | |
] | |
} | |
}, | |
confirmingWithUser: { | |
entry: 'displayUi', | |
invoke: {src: 'invokeCreateChannelConfirmation', onDone: 'branchingOnRole'} | |
}, | |
checkingBudget: {invoke: {src: 'checkBudget', onDone: 'branchingOnRole', onError: 'failure'}}, | |
branchingOnRole: { | |
on: { | |
'': [ | |
{ | |
target: 'creatingChannel', | |
cond: {name: 'amCreator', predicate: () => true, type: 'xstate.guard'} | |
}, | |
{ | |
target: 'joiningChannel', | |
cond: {name: 'amJoiner', predicate: () => true, type: 'xstate.guard'} | |
} | |
] | |
} | |
}, | |
creatingChannel: { | |
invoke: { | |
data: (_, event) => event.data, | |
src: 'createChannel', | |
onDone: { | |
target: 'openChannelAndFundProtocol', | |
actions: ['assignChannelId', 'spawnObservers', 'sendCreateChannelResponse'] | |
} | |
} | |
}, | |
joiningChannel: { | |
entry: ['spawnObservers'], | |
invoke: {src: 'signFirstState', onDone: 'openChannelAndFundProtocol'}, | |
exit: ['sendJoinChannelResponse'] | |
}, | |
openChannelAndFundProtocol: { | |
initial: 'getDataForCreateChannelAndFund', | |
states: { | |
getDataForCreateChannelAndFund: { | |
invoke: { | |
src: 'getDataForCreateChannelAndFund', | |
onDone: 'invokeCreateChannelAndFundProtocol' | |
} | |
}, | |
invokeCreateChannelAndFundProtocol: { | |
invoke: { | |
id: undefined, | |
src: 'invokeCreateChannelAndFundProtocol', | |
data: (_, {data}) => data, | |
onDone: 'done', | |
autoForward: true | |
} | |
}, | |
done: {type: 'final'} | |
}, | |
onDone: 'running' | |
}, | |
running: { | |
entry: ['hideUi'], | |
on: { | |
SPAWN_OBSERVERS: {actions: ['spawnObservers']}, | |
PLAYER_STATE_UPDATE: { | |
target: 'running', | |
actions: ['updateStoreWithPlayerState', 'sendUpdateChannelResponse'] | |
}, | |
CHANNEL_UPDATED: [ | |
{ | |
target: 'closing', | |
cond: {name: 'channelClosing', predicate: () => true, type: 'xstate.guard'} | |
} | |
], | |
PLAYER_REQUEST_CONCLUDE: {target: 'closing'} | |
} | |
}, | |
closing: { | |
entry: 'displayUi', | |
exit: 'hideUi', | |
invoke: { | |
id: 'closing-protocol', | |
src: 'invokeClosingProtocol', | |
data: context => context, | |
autoForward: true, | |
onDone: {target: 'done', actions: ['sendCloseChannelResponse']} | |
} | |
}, | |
done: {type: 'final'}, | |
failure: {} | |
} | |
}; | |
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