Skip to content

Instantly share code, notes, and snippets.

@gustavo-depaula
Created October 28, 2019 19:03
Show Gist options
  • Save gustavo-depaula/ea7d358944cff96c62692625ab2e73c0 to your computer and use it in GitHub Desktop.
Save gustavo-depaula/ea7d358944cff96c62692625ab2e73c0 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const SSTATES = {
loadingStep: 'loadingStep',
successStep: 'successStep',
offlineStep: 'offlineStep',
redirectStep: 'redirectStep'
};
const AACTIONS = {
REDIRECT: 'REDIRECT'
};
const promise = () => {
return new Promise((resolve) => {
resolve()
})
}
const packageSyncMachine = Machine({
id: 'packageSync',
initial: SSTATES.loadingStep,
context: {
barcode: null,
status: null,
receiverName: null,
receiverDocument: null,
receiverSignature: null
},
states: {
[SSTATES.loadingStep]: {
on: {
ONLINE: SSTATES.successStep,
OFFLINE: SSTATES.offlineStep
},
invoke: {
id: 'updateStatus',
src: context => promise(),
onDone: {
actions: send('OFFLINE')
},
onError: {
actions: [
sendParent('SET_NOTIFICATION'),
sendParent('BACK')
]
}
}
},
[SSTATES.successStep]: {
on: {
[AACTIONS.REDIRECT]: SSTATES.redirectStep
}
},
[SSTATES.offlineStep]: {
on: {
[AACTIONS.REDIRECT]: SSTATES.redirectStep
}
},
[SSTATES.redirectStep]: {}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment