Last active
September 3, 2020 20:04
-
-
Save austinsamsel/6a967f64b88975fb4fa6b20ccf055ee7 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', | |
DONE: 'done', | |
} | |
Machine({ | |
id: 'openPack', | |
initial: 'idle', | |
states: { | |
[FS.IDLE]: { | |
on: { OPEN_PACK: '#openPack.opening' }, | |
}, | |
[FS.UNSEALED_RESET]: { | |
on: { RETRY: '#openPack.getting_moments' }, | |
}, | |
[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: 'pollingPack' }), | |
}, | |
}, | |
invoke: { | |
id: 'pollingPack', | |
src: 'pollPack', | |
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: { | |
target: '#openPack.idle', | |
actions: 'opened', | |
}, | |
onError: { | |
target: '#openPack.unsealed_reset', | |
actions: 'setErrorMessage', | |
}, | |
}, | |
}, | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment