Created
August 9, 2019 16:53
-
-
Save derek-duncan/e511b7a2ecbc899489231e393fe66f98 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
// Available variables: | |
// - Machine | |
// - interpret | |
// - assign | |
// - send | |
// - sendParent | |
// - spawn | |
// - raise | |
// - actions | |
// - XState (all XState exports) | |
const fetchMachine = Machine({ | |
type: 'parallel', | |
states: { | |
Upload: { | |
initial: 'DropIdle', | |
states: { | |
DropIdle: { | |
onEntry: ['resetDrop'], | |
on: { | |
DROP_START: 'DropActive', | |
}, | |
}, | |
DropActive: { | |
onEntry: ['startDrop'], | |
on: { | |
DROP_CANCEL: 'DropIdle', | |
DROP_REJECT: 'DropRejected', | |
DROP_ACCEPT: 'DropAccepted', | |
}, | |
}, | |
DropRejected: { | |
onEntry: ['rejectDrop', 'delayDropReset'], | |
on: { | |
DROP_RESET: 'DropIdle', | |
}, | |
}, | |
DropAccepted: { | |
onEntry: ['acceptDrop', 'processTokens'], | |
on: { | |
PROCESS_NEW_TOKENS_SUCCESS: 'DropIdle', | |
PROCESS_NEW_TOKENS_FAIL: 'DropRejected', | |
}, | |
}, | |
}, | |
}, | |
TokenLookup: { | |
initial: 'TokenLookupIdle', | |
states: { | |
TokenLookupIdle: { | |
onEntry: ['startTokenLookupTimer'], | |
onExit: ['stopTokenLookupTimer'], | |
on: { | |
TOKEN_LOOKUP_START: [ | |
{cond: 'isAutoAuthAvailable', target: 'TokenLookupPending'}, | |
{target: 'TokenLookupIdle'}, | |
], | |
}, | |
}, | |
TokenLookupPending: { | |
onEntry: ['startPending', 'searchForPracticeToken'], | |
onExit: ['stopPending'], | |
on: { | |
TOKEN_LOOKUP_CANCEL: 'TokenLookupIdle', | |
PROCESS_NEW_TOKENS_FAIL: 'TokenLookupIdle', | |
PROCESS_NEW_TOKENS_SUCCESS: 'TokenLookupIdle', | |
}, | |
initial: 'TokenLookupPendingSearching', | |
states: { | |
TokenLookupPendingSearching: { | |
on: { | |
PROCESS_NEW_TOKENS: 'TokenLookupPendingProcessing', | |
}, | |
}, | |
TokenLookupPendingProcessing: { | |
onEntry: ['processTokens'], | |
}, | |
}, | |
}, | |
}, | |
}, | |
AuthStatus: { | |
initial: 'AuthStatusBoot', | |
on: { | |
REBOOT: '.AuthStatusBoot', | |
}, | |
states: { | |
AuthStatusBoot: { | |
on: { | |
'': [ | |
{cond: 'hasValidToken', target: 'Authenticated'}, | |
{target: 'Unauthenticated'}, | |
], | |
}, | |
}, | |
Unauthenticated: { | |
onEntry: ['setUnauthenticated'], | |
on: { | |
PROCESS_NEW_TOKENS_SUCCESS: { | |
target: 'Authenticated', | |
actions: ['setNewPractice'], | |
}, | |
}, | |
initial: 'UnauthenticatedBoot', | |
states: { | |
UnauthenticatedBoot: { | |
on: { | |
'': [ | |
{cond: 'isAutoAuthAvailable', target: 'AutoInput'}, | |
{target: 'ManualInput'}, | |
], | |
}, | |
}, | |
AutoInput: { | |
onEntry: ['setAuto'], | |
on: { | |
USE_MANUAL: { | |
target: 'ManualInput', | |
actions: ['showManualCancel'], | |
}, | |
}, | |
}, | |
ManualInput: { | |
onEntry: ['setManual'], | |
on: { | |
CANCEL_MANUAL: 'UnauthenticatedBoot', | |
}, | |
initial: 'ManualIdle', | |
states: { | |
ManualIdle: { | |
onEntry: ['maybeSetError'], | |
on: { | |
PROCESS_NEW_TOKENS_FAIL: 'ManualIdle', | |
MANUAL_AUTH_SUBMIT: 'ManualPending', | |
}, | |
}, | |
ManualPending: { | |
onEntry: ['startPending', 'processTokens'], | |
onExit: ['stopPending'], | |
on: { | |
PROCESS_NEW_TOKENS_FAIL: 'ManualIdle', | |
}, | |
}, | |
}, | |
}, | |
}, | |
}, | |
Authenticated: { | |
onEntry: ['setAuthenticated', 'setupPractice'], | |
on: { | |
CHANGE_PRACTICE: { | |
target: 'Unauthenticated', | |
actions: ['changePractice'], | |
}, | |
PRACTICE_LOGOUT: { | |
target: 'Unauthenticated', | |
actions: ['clearPractice'], | |
}, | |
PROCESS_NEW_TOKENS_SUCCESS: { | |
target: 'Authenticated', | |
actions: ['setNewPractice'], | |
}, | |
}, | |
initial: 'RefreshPractices', | |
states: { | |
RefreshPractices: { | |
initial: 'RefreshPracticesIdle', | |
states: { | |
RefreshPracticesIdle: { | |
onEntry: ['startRefreshPracticesTimer'], | |
onExit: ['stopRefreshPracticesTimer'], | |
on: { | |
REFRESH_PRACTICES_START: 'RefreshPracticesPending', | |
}, | |
}, | |
RefreshPracticesPending: { | |
onEntry: ['refreshPractices'], | |
onExit: ['setupPractice'], | |
on: { | |
REFRESH_PRACTICES_COMPLETE: 'RefreshPracticesIdle', | |
}, | |
}, | |
}, | |
}, | |
}, | |
}, | |
}, | |
} | |
}, | |
}, { | |
guards: { | |
hasValidToken() { | |
return false; | |
}, | |
isAutoAuthAvailable() { | |
return false; | |
} | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment