Created
April 28, 2021 15:13
-
-
Save devtrillo/c1e6e855b96dc9c3ed973b79e1614e55 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains hidden or 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 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