Skip to content

Instantly share code, notes, and snippets.

@davidkpiano
Created August 28, 2020 10:33
Show Gist options
  • Save davidkpiano/66a0b60f0798af57c8a93cde53bfc66c to your computer and use it in GitHub Desktop.
Save davidkpiano/66a0b60f0798af57c8a93cde53bfc66c to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const auth = Machine({
id: 'auth',
initial: 'authenticating',
states: {
authenticating: {
after: {
1000: 'authenticated'
}
},
authenticated: {
entry: sendParent('TOKEN')
}
}
});
const server = Machine({
id: 'server',
initial: 'idle',
states: {
idle: {
on: {
TOKEN: {
actions: sendParent('USER', { delay: 1000 })
}
}
}
}
});
const client = Machine({
id: 'client',
initial: 'login',
invoke: {
id: 'server',
src: server
},
states: {
login: {
on: {
LOGIN: 'auth'
}
},
auth: {
invoke: {
id: 'auth',
src: auth
},
on: {
TOKEN: 'fetchUser'
}
},
fetchUser: {
entry: send('TOKEN', { to: 'server' }),
on: {
USER: 'success'
}
},
success: {}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment