Created
February 12, 2020 21:19
-
-
Save brookslybrand/8d548942a35d45ccd1eaeb23adaf4382 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 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