Last active
September 3, 2020 16:01
-
-
Save austinsamsel/f04d8d5996da367d446c5da8ec4c9129 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains hidden or 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 IGNORE_ERRORS_DURATION = 3000 | |
const FS = { | |
IDLE: 'idle', | |
UNSEALED_RESET: 'unsealed_reset', | |
OPENING: 'opening', | |
UNSEALED_RETRYING: 'unsealed_retrying', | |
POLLING_PACK: 'polling_pack', | |
GETTING_MOMENTS: 'getting_moments', | |
SUCCESS: 'success', | |
} | |
Machine({ | |
id: 'openPack', | |
initial: 'idle', | |
states: { | |
[FS.IDLE]: { | |
on: { OPEN_PACK: '#openPack.opening' }, | |
}, | |
[FS.UNSEALED_RESET]: { | |
on: { RETRY: '#openPack.polling_pack' }, | |
}, | |
[FS.OPENING]: { | |
invoke: { | |
id: 'opening', | |
src: 'openPack', | |
onDone: 'polling_pack', | |
onError: { | |
target: '#openPack.idle', | |
actions: 'setErrorMessage', | |
}, | |
}, | |
}, | |
[FS.POLLING_PACK]: { | |
after: { | |
[IGNORE_ERRORS_DURATION]: { | |
actions: send('STOP', { to: 'pollPack' }), | |
}, | |
}, | |
invoke: { | |
id: 'pollPack', | |
src: 'pollPackSuccess', | |
onError: { | |
target: '#openPack.unsealed_reset', | |
actions: 'setErrorMessage', | |
}, | |
}, | |
on: { | |
PACK_POLL_ERROR: { | |
target: '#openPack.unsealed_reset', | |
actions: 'setErrorMessage', | |
}, | |
PACK_POLL_SUCCESS: '#openPack.getting_moments', | |
}, | |
}, | |
[FS.GETTING_MOMENTS]: { | |
invoke: { | |
id: 'getting_moments', | |
src: 'getMoments', | |
onDone: '#openPack.success', | |
onError: { | |
target: '#openPack.unsealed_reset', | |
actions: 'setErrorMessage', | |
}, | |
}, | |
}, | |
[FS.SUCCESS]: { | |
type: 'final', | |
entry: 'opened', | |
}, | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment