Skip to content

Instantly share code, notes, and snippets.

@schpet
Created February 8, 2021 16:58
Show Gist options
  • Save schpet/c44d8eba356b5685a6ec133dcddd3e40 to your computer and use it in GitHub Desktop.
Save schpet/c44d8eba356b5685a6ec133dcddd3e40 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: "contacts",
initial: "pending",
context: {
contacts: undefined,
},
states: {
pending: { on: { INITIATE: "permission_requested", SKIP: "skipped" } },
permission_requested: {
invoke: {
src: "requestPermission",
onDone: { target: "reading_contacts" },
onError: { target: "permission_denied" },
},
},
reading_contacts: {
invoke: {
src: "saveContacts",
onDone: "pending",
onError: "failed",
},
},
complete: {
type: "final",
},
skipped: {
invoke: {
src: "skip",
onDone: "pending",
},
},
failed: { on: { RETRY: "permission_requested", SKIP: "skipped" } },
permission_denied: {
on: { RETRY: "permission_requested", SKIP: "skipped" },
},
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment