Last active
March 11, 2021 16:08
-
-
Save austinsamsel/26339c44aab06debcc1e19c8575e80ba 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', | |
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: 'isPackUnsealed', | |
}, | |
{ | |
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: { | |
isPackUnsealed: (context, event) => { | |
return event?.data?.i18nKey === ERRORS.ALREADY_OPENED; | |
}, | |
}, | |
}, | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment