Skip to content

Instantly share code, notes, and snippets.

@devtrillo
Created April 28, 2021 15:13
Show Gist options
  • Save devtrillo/c1e6e855b96dc9c3ed973b79e1614e55 to your computer and use it in GitHub Desktop.
Save devtrillo/c1e6e855b96dc9c3ed973b79e1614e55 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: "barcodeScanner",
initial: "requestPermission",
context: {
hasPermission: false,
timesAskedPermission: 0,
barcodes: [],
overlays: {},
},
states: {
idle: {
on: {
"": [
{ target: "scanning", cond: "hasPermission" },
{ target: "noPermission", cond: "noPermission" },
{ target: "requestPermission" },
],
},
},
requestPermission: {
invoke: {
id: "requestPermission",
src: "requestPermission",
onDone: { target: "idle", actions: "savePermission" },
onError: { target: "noPermission", actions: "accumulateTimesAsked" },
},
},
noPermission: {},
scanning: {
invoke: { src: "clearBounds" },
on: {
STOP_SCANNING: "done",
NEW_BARCODE: {
actions: ["saveNewBarcode"],
},
},
},
done: { type: "final" },
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment