Created
April 16, 2021 15:31
-
-
Save elmarburke/e3d6aec65d2329756c97e38bd3bde418 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 nestMachine = Machine({ | |
id: 'nest', | |
initial: 'initial', | |
context: { | |
user: null, | |
}, | |
states: { | |
initial: { | |
on: { SIGN_IN: { target: 'dashboard', actions: ['signIn'] } }, | |
}, | |
dashboard: { | |
on: { SIGN_OUT: 'initial' }, | |
}, | |
}, | |
}, | |
{ | |
actions: { | |
signIn: assign((context, event) => { | |
if (event.type !== 'SIGN_IN') return context; | |
const name = | |
event.email.split('@')[0]?.split('.').join(' ') ?? event.email; | |
return { | |
user: { name, email: event.email }, | |
}; | |
}), | |
}, | |
},); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment