Last active
January 15, 2021 10:00
-
-
Save tomraithel/18b01eee9d63a438146742cd667fc5f6 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 loggedInState = { | |
initial: 'idle', | |
states: { | |
idle: { | |
on: { | |
load: 'loading' | |
} | |
}, | |
loading: { | |
invoke: { | |
id: 'fetchData', | |
src: 'fetchData', | |
}, | |
on: { | |
success: [ | |
{ | |
target: 'idle', | |
actions: ['updateData'] | |
}, | |
], | |
error: { target: 'idle', actions: ['setError'] | |
}, | |
}, | |
}, | |
} | |
}; | |
Machine({ | |
id: 'App State', | |
initial: 'loadingIdentity', | |
context: { | |
identity: null | |
}, | |
states: { | |
loadingIdentity: { | |
invoke: { | |
id: 'fetchIdentity', | |
src: 'fetchIdentity', | |
}, | |
on: { | |
success: [ | |
{ | |
target: 'loggedIn', | |
cond: 'hasIdentity', | |
actions: ['setIdentity'] | |
}, | |
{ | |
target: 'notLoggedIn', | |
cond: 'hasNoIdentity', | |
actions: ['clearIdentity'] | |
}, | |
], | |
error: { target: 'error', actions: ['clearIdentity'] | |
}, | |
}, | |
}, | |
loggedIn: { | |
...loggedInState | |
}, | |
notLoggedIn: { | |
type: 'final' | |
}, | |
error: { | |
on: { | |
FETCH: 'loadingIdentity' | |
} | |
} | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment