Skip to content

Instantly share code, notes, and snippets.

@korshunad
Created April 10, 2021 03:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save korshunad/687036ad21372ca0347bf1dba18e2af5 to your computer and use it in GitHub Desktop.
Save korshunad/687036ad21372ca0347bf1dba18e2af5 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
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