Skip to content

Instantly share code, notes, and snippets.

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 = {
@andrewgordstewart
andrewgordstewart / machine.js
Last active March 12, 2020 21:55
Generated by XState Viz: https://xstate.js.org/viz
const config = {
key: 'ledger-funding',
initial: 'acquiringLock',
states: {
acquiringLock: {
invoke: {src: 'acquireLock', onDone: 'fundingTarget'},
exit: {type: 'xstate.assign', assignment: {lock: (_, event) => event.data}}
},
fundingTarget: {
initial: 'getTargetOutcome',
const config = {
key: 'virtual-defunding-as-leaf',
initial: 'checkChannels',
states: {
checkChannels: {
invoke: {src: 'checkChannelsService', onDone: 'closeTarget'},
exit: {type: 'xstate.assign', assignment: (_, {data}) => data}
},
closeTarget: {
initial: 'finalTargetState',
const config = {"key":"create-and-direct-fund","initial":"preFundSetup","states":{"preFundSetup":{"invoke":{"id":"preFundSetup","src":"advanceChannel","data":({ channelId }) => ({
channelId,
targetTurnNum: i
}),"onDone":"depositing"}},"depositing":{"initial":"getDepositingInfo","states":{"getDepositingInfo":{"invoke":{"src":"getDepositingInfo","onDone":"invokeDepositing"}},"invokeDepositing":{"invoke":{"id":undefined,"src":"invokeDepositing","data":(_, { data }) => data,"onDone":"done","autoForward":true}},"done":{"type":"final"}},"onDone":"postFundSetup"},"postFundSetup":{"invoke":{"id":"postFundSetup","src":"advanceChannel","data":({ channelId }) => ({
channelId,
targetTurnNum: i
}),"onDone":"success"}},"success":{"type":"final"}}}
const guards = {}
const customActions = {}
const config = {
key: 'create-and-fund',
initial: 'preFundSetup',
on: {'xstate.error': {target: 'failure'}},
states: {
preFundSetup: {
initial: 'getPreFundSetup',
states: {
getPreFundSetup: {
invoke: {src: 'getPreFundSetup', onDone: 'supportState', onError: undefined}
const config = {
id: 'application-workflow',
initial: 'initializing',
on: {CHANNEL_UPDATED: {actions: ['sendChannelUpdatedNotification']}},
states: {
initializing: {
entry: 'displayUi',
on: {
CREATE_CHANNEL: {target: 'confirmCreateChannelWorkflow', actions: ['assignChannelParams']},
JOIN_CHANNEL: {target: 'confirmJoinChannelWorkflow'}
const config = {
id: 'application-workflow',
initial: 'initializing',
on: {CHANNEL_UPDATED: {actions: ['sendChannelUpdatedNotification']}},
states: {
initializing: {
entry: 'displayUi',
on: {
CREATE_CHANNEL: {target: 'createChannelInStore', actions: ['assignChannelParams']},
JOIN_CHANNEL: {target: 'joinChannel'}
const config = {
key: 'virtual-funding-as-leaf',
id: 'workflow',
initial: 'setupJointChannel',
states: {
setupJointChannel: {
initial: 'waitForFirstJointState',
states: {
waitForFirstJointState: {
invoke: {
const config = {
key: 'virtual-funding-as-hub',
id: 'workflow',
initial: 'setupJointChannel',
states: {
setupJointChannel: {
initial: 'waitForFirstJointState',
states: {
waitForFirstJointState: {
invoke: {
@andrewgordstewart
andrewgordstewart / machine.js
Last active February 21, 2020 16:52
Generated by XState Viz: https://xstate.js.org/viz
const machine = Machine({
id: 'stepMachine',
initial: 'step1',
on: {
// Accepted in step1, step2 or step3
FINISH_MACHINE: 'step3'
},
states: {
step1: {
initial: 'a',