Skip to content

Instantly share code, notes, and snippets.

@brookslybrand
Created February 12, 2020 21:19
Show Gist options
  • Save brookslybrand/8d548942a35d45ccd1eaeb23adaf4382 to your computer and use it in GitHub Desktop.
Save brookslybrand/8d548942a35d45ccd1eaeb23adaf4382 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const initialContext = {
displayName: '',
email: ''
}
const userMachine = Machine(
{
id: 'user',
initial: 'unchecked',
context: initialContext,
on: {
LOGOUT: 'loggedOut',
LOGIN: 'loggedIn'
},
states: {
unchecked: {},
loggedOut: {
entry: 'clearUserData'
},
loggedIn: {
entry: 'addUserData'
}
}
},
{
actions: {
clearUserData: assign(initialContext),
addUserData: assign((context, event) => ({
displayName: event.displayName,
email: event.email
}))
}
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment