Skip to content

Instantly share code, notes, and snippets.

@NikitaIT
Created July 11, 2020 14:31
Show Gist options
  • Save NikitaIT/c2e74af2d84393084ec05d4b12359713 to your computer and use it in GitHub Desktop.
Save NikitaIT/c2e74af2d84393084ec05d4b12359713 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
const fetchMachine = Machine(
{
id: "authentication",
initial: "unauthorized",
context: {
user: undefined,
message: undefined,
},
states: {
unauthorized: {
entry: "resetUser",
on: {
LOGIN: "loading",
SIGNUP: "signup",
},
},
signup: {
invoke: {
src: "performSignup",
onDone: { target: "unauthorized", actions: "onSuccess" },
onError: { target: "unauthorized", actions: "onError" },
},
},
loading: {
invoke: {
src: "performLogin",
onDone: { target: "authorized", actions: "onSuccess" },
onError: { target: "unauthorized", actions: "onError" },
},
},
updating: {
invoke: {
src: "updateProfile",
onDone: { target: "refreshing" },
onError: { target: "unauthorized", actions: "onError" },
},
},
refreshing: {
invoke: {
src: "getUserProfile",
onDone: { target: "authorized", actions: "setUserProfile" },
onError: { target: "unauthorized", actions: "onError" },
},
on: {
LOGOUT: "logout",
},
},
logout: {
invoke: {
src: "performLogout",
onDone: { target: "unauthorized" },
onError: { target: "unauthorized", actions: "onError" },
},
},
authorized: {
entry: "redirectHomeAfterLogin",
on: {
UPDATE: "updating",
REFRESH: "refreshing",
LOGOUT: "logout",
},
},
},
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment