Skip to content

Instantly share code, notes, and snippets.

@adamterlson
Created April 21, 2020 19:05
Show Gist options
  • Save adamterlson/2a8317e74c305718847b4ce98c05c8bb to your computer and use it in GitHub Desktop.
Save adamterlson/2a8317e74c305718847b4ce98c05c8bb to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const transactionMachine = Machine({
id: 'transaction',
initial: 'draft',
states: {
draft: {
on: {
AUTHORIZE_PAYMENT: {
target: 'authorizing',
},
ADD_ITEM: {
target: 'draft',
},
ADD_CUSTOMER: {
target: 'draft',
},
TRANSFER: 'transferred',
},
},
authorizing: {
on: {
AUTHORIZED: 'finalizing'
}
},
finalizing: {
on: {
COMPLETE: 'completed',
}
},
error: {
on: {
RETRY: {
target: 'draft',
},
TRANSFER: 'transferred',
},
},
transferred: {
type: 'final',
},
completed: {
type: 'final',
},
},
})
const activityStates = {
id: 'activity',
initial: 'idle',
states: {
idle: {
on: {
CREATE_TRANSACTION: 'transaction'
}
},
transaction: {
invoke: {
src: transactionMachine,
onDone: 'idle',
onError: 'idle',
}
}
}
}
const socketMachine = Machine({
id: 'socket',
initial: 'disconnected',
states: {
disconnected: {
on: {
CONNECT: 'connected'
}
},
connected: {
...activityStates,
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment