Created
August 28, 2020 10:33
-
-
Save davidkpiano/66a0b60f0798af57c8a93cde53bfc66c 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 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