Skip to content

Instantly share code, notes, and snippets.

@amirrustam
Created March 24, 2020 18:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amirrustam/230a84f8a8db7c0dd898eedc96a18cd9 to your computer and use it in GitHub Desktop.
Save amirrustam/230a84f8a8db7c0dd898eedc96a18cd9 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 authMachine = Machine({
id: "authentication",
initial: "unauthorized",
context: {},
states: {
unauthorized: {
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: "authorized", actions: ["onSuccess"] },
onError: { target: "unauthorized", actions: "onError" }
}
},
refreshing: {
invoke: {
src: "getUserProfile",
onDone: { target: "authorized" },
onError: { target: "unauthorized", actions: "onError" }
}
},
authorized: {
invoke: {
src: "getUserProfile",
onDone: { actions: ["setUserProfile"] },
onError: { actions: "onError" }
},
on: {
UPDATE: "updating",
REFRESH: "refreshing",
LOGOUT: "unauthorized"
}
}
}
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment