Skip to content

Instantly share code, notes, and snippets.

@elmarburke
Created April 16, 2021 15:31
Show Gist options
  • Save elmarburke/e3d6aec65d2329756c97e38bd3bde418 to your computer and use it in GitHub Desktop.
Save elmarburke/e3d6aec65d2329756c97e38bd3bde418 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
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