Created
April 10, 2021 03:06
-
-
Save korshunad/687036ad21372ca0347bf1dba18e2af5 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 IGNORE_ERRORS_DURATION = 3000; | |
const FS = { | |
IDLE: 'idle', | |
UNSEALED_RESET: 'unsealed_reset', | |
UNSEALED_ERROR: 'unsealed_error', | |
OPENING: 'opening', | |
GETTING_MOMENTS: 'getting_moments', | |
} | |
const ERRORS = { | |
ALREADY_OPENED: 'PackModal.openPack.errors.alreadyOpened' | |
} | |
Machine( | |
{ | |
id: 'openPack', | |
initial: 'idle', | |
states: { | |
[FS.IDLE]: { | |
on: { | |
OPEN_PACK: [{ target: '#openPack.opening' }], | |
}, | |
}, | |
[FS.UNSEALED_RESET]: { | |
on: { RETRY: '#openPack.opening' }, | |
}, | |
[FS.UNSEALED_ERROR]: { | |
on: { RESET: '#openPack.idle' }, | |
}, | |
[FS.OPENING]: { | |
invoke: { | |
id: 'opening', | |
src: 'openPack', | |
onDone: '#openPack.getting_moments', | |
onError: [ | |
{ | |
target: '#openPack.unsealed_error', | |
actions: 'setErrorMessage', | |
cond: 'isNoRetry', | |
}, | |
{ | |
target: '#openPack.idle', | |
actions: 'setErrorMessage', | |
}, | |
], | |
}, | |
}, | |
[FS.GETTING_MOMENTS]: { | |
invoke: { | |
id: 'getting_moments', | |
src: 'getMoments', | |
onDone: { | |
target: '#openPack.idle', | |
actions: 'opened', | |
}, | |
onError: { | |
target: '#openPack.unsealed_reset', | |
actions: 'setErrorMessage', | |
}, | |
}, | |
}, | |
}, | |
}, | |
{ | |
guards: { | |
isNoRetry: (context, event) => { | |
return ( | |
event?.data?.i18nKey === ERRORS.ALREADY_OPENED || | |
event?.data?.i18nKey === ERRORS.FEATURE_FLAG_ERROR | |
); | |
}, | |
}, | |
}, | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment