Last active
February 14, 2020 12:24
-
-
Save iamstarkov/8f52126481d9bcdc799549dcf943fb54 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 fetchMachine = Machine( | |
{ | |
id: 'OAUTH CLIENT', | |
type: 'parallel', | |
context: { | |
hasAuthorizationCode: true | |
}, | |
states: { | |
AUTHORIZED: { | |
id: 'authed', | |
initial: 'FALSE', | |
states: { | |
TRUE: { | |
// on: | |
}, | |
FALSE: {} | |
} | |
}, | |
CALLBACK: { | |
initial: 'INIT', | |
id: 'callback', | |
states: { | |
'INIT': { | |
on: { | |
'*': [ | |
{ | |
target: 'REQUESTING ACCESS TOKEN', | |
cond: 'hasAuthorizationCode' | |
}, | |
{ | |
target: '#authed.FALSE' | |
} | |
] | |
} | |
}, | |
'REQUESTING ACCESS TOKEN': { | |
id: 'access_token', | |
entry: 'exchangeAuthCodeForAccessToken', | |
initial: 'idle', | |
states: { | |
idle: { | |
on: { | |
FETCH: 'loading' | |
} | |
}, | |
loading: { | |
on: { | |
RESOLVE: 'success', | |
REJECT: 'failure' | |
} | |
}, | |
success: { | |
type: 'final', | |
onEntry: send('SUCC'), | |
}, | |
failure: { | |
type: 'final', | |
onEntry: send('FAIL'), | |
} | |
}, | |
on: { | |
SUCC: 'REQUESTING SESSION', | |
FAIL: '#authed.FALSE' | |
} | |
}, | |
'REQUESTING SESSION': { | |
entry: 'exchangeAccessTokenForSession', | |
on: { | |
SUCC: { | |
target: [ | |
'#authed.TRUE', | |
'SESSION RECEIVED' | |
] | |
}, | |
FAIL: '#authed.FALSE' | |
} | |
}, | |
'SESSION RECEIVED': { | |
type: 'final', | |
} | |
} | |
} | |
} | |
}, | |
{ guards: { hasAuthorizationCode: ctx => ctx.hasAuthorizationCode } } | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment