Created
March 24, 2020 18:27
-
-
Save amirrustam/230a84f8a8db7c0dd898eedc96a18cd9 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
// 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