Created
October 28, 2019 19:03
-
-
Save gustavo-depaula/ea7d358944cff96c62692625ab2e73c0 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 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