Skip to content

Instantly share code, notes, and snippets.

@schpet
Created May 6, 2021 01:49
Show Gist options
  • Save schpet/7fe129af3f09952617fb0c96a5bc2a5c to your computer and use it in GitHub Desktop.
Save schpet/7fe129af3f09952617fb0c96a5bc2a5c 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: "nudge",
},
},
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",
},
nudge: {
on: {
INITIATE: "permission_requested",
SKIP: "skipped",
DISMISS: "pending",
},
entry: ["showNudgeSheet"],
exit: ["hideNudgeSheet"],
},
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