Skip to content

Instantly share code, notes, and snippets.

@tomraithel
Last active January 15, 2021 10:00
Show Gist options
  • Save tomraithel/18b01eee9d63a438146742cd667fc5f6 to your computer and use it in GitHub Desktop.
Save tomraithel/18b01eee9d63a438146742cd667fc5f6 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
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