Created
April 24, 2023 07:51
-
-
Save lenka21/a64d330ca57629693d88e21a7c6f7c97 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
// Available variables: | |
// - Machine | |
// - interpret | |
// - assign | |
// - send | |
// - sendParent | |
// - spawn | |
// - raise | |
// - actions | |
// - XState (all XState exports) | |
const fetchMachine = Machine( | |
{ | |
id: 'setup', | |
initial: 'login', | |
context: { | |
isExitModalVisible: false, | |
exitConfirmed: false, | |
exitReason: undefined | |
}, | |
states: { | |
login: { | |
on: { | |
LOADING: 'inProgress.waiting', | |
EXIT: { | |
target: 'exiting', | |
actions: ['rememberExitReason'] | |
} | |
} | |
}, | |
inProgress: { | |
states: { | |
waiting: { | |
initial: 'idle', | |
states: { | |
idle: { | |
on: { | |
LOGIN_FINISHED: '#setup.inProgress.waiting.ready', | |
PLAY: 'gameIsPlayed', | |
DUAL_AUTH_REQUIRED: '#setup.inProgress.dualAuth' | |
} | |
}, | |
gameIsPlayed: { | |
initial: 'needsToWait', | |
states: { | |
needsToWait: { | |
on: { | |
LOGIN_FINISHED: 'sourceIsReady', | |
DUAL_AUTH_REQUIRED: 'dualAuthRequired' | |
} | |
}, | |
dualAuthRequired: { | |
type: 'final', | |
on: { | |
CONTINUE: '#setup.inProgress.dualAuth' | |
} | |
}, | |
sourceIsReady: { | |
type: 'final', | |
on: { | |
CONTINUE: '#setup.inProgress.waiting.ready' | |
} | |
} | |
} | |
}, | |
ready: { | |
type: 'final', | |
invoke: { | |
src: () => (send) => send('REALLY_READY') | |
}, | |
on: { | |
REALLY_READY: '#setup.success' | |
} | |
} | |
} | |
}, | |
dualAuth: { | |
on: { | |
DUAL_AUTH_SUCCESS: 'waiting' | |
} | |
} | |
}, | |
on: { | |
MANUAL_ACTION_REQUIRED: '#setup.manualActionRequired', | |
CAPTCHA: '#setup.captcha', | |
ERROR: { target: '#setup.error', actions: ['notify'] }, | |
EXIT: { | |
actions: ['rememberExitReason', 'openExitModal'] | |
}, | |
CONFIRM_EXIT: { | |
cond: (context) => context.isExitModalVisible, | |
target: 'exiting', | |
actions: ['closeExitModal'] | |
}, | |
CANCEL_EXIT: { | |
actions: ['forgetExitReason', 'closeExitModal'] | |
} | |
} | |
}, | |
manualActionRequired: {}, | |
captcha: {}, | |
success: { | |
entry: () => { | |
push({ name: SOURCES_ROUTE_NAME }) | |
} | |
}, | |
error: { | |
entry: () => { | |
send('RETRY') | |
}, | |
on: { | |
RETRY: 'login' | |
} | |
}, | |
exiting: { | |
type: 'final', | |
entry: () => { | |
push({ name: SOURCES_ROUTE_NAME }) | |
} | |
} | |
} | |
}, | |
{ | |
actions: { | |
notify: () => { | |
notify({ title: t('scrapers:notifications.loginFailed'), type: 'danger' }) | |
}, | |
openExitModal: (context) => { | |
context.isExitModalVisible = true | |
}, | |
closeExitModal: (context) => { | |
context.isExitModalVisible = false | |
}, | |
rememberExitReason: (context, event) => { | |
if (event.type === 'EXIT') { | |
context.exitReason = event.telemetryEvent | |
} | |
}, | |
forgetExitReason: (context) => { | |
context.exitReason = undefined | |
} | |
} | |
} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment