Skip to content

Instantly share code, notes, and snippets.

@gustavo-depaula
Created October 28, 2019 19:03
Show Gist options
  • Save gustavo-depaula/e1d17cbae7055efca529a45cf1ef548f to your computer and use it in GitHub Desktop.
Save gustavo-depaula/e1d17cbae7055efca529a45cf1ef548f to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const protocolMachine = Machine(
{
id: 'protocol',
initial: 'signature',
context: {
// machine refs
signatureMachineRef: null,
recipientMachineRef: null,
packageSyncMachineRef: null,
// data
status: '1', // delivered
signature: null,
isExpectedRecipient: null,
pkg: null,
name: null,
document: null
},
states: {
signature: {
entry: ['spawnSignatureMachine'],
on: {
'SIGNATURE.INFO': {
actions: [
'saveSignatureData',
'redirectAccordingToIsExpectedRecipient'
]
},
GET_RECIPIENT_INFO: 'recipient',
UPDATE_PACKAGE_STATUS: 'packageSync',
BACK: {
actions: ['goBack']
}
}
},
recipient: {
entry: ['spawnRecipientMachine'],
on: {
BACK: 'signature',
'RECIPIENT.INFO': {
target: 'packageSync',
actions: ['saveRecipientData']
}
}
},
packageSync: {
entry: ['spawnPackageSyncMachine'],
on: {
BACK: 'signature',
SET_NOTIFICATION: {
actions: ['setNotification']
}
}
}
},
on: {
CLEAN_NOTIFICATION: {
actions: ['cleanNotification']
}
}
},
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment