Last active
January 23, 2020 14:48
-
-
Save MilanLempera/935ebb26b6ab022080bb2784344f1291 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: "scanner", | |
| initial: "readOnlyView", | |
| context: { | |
| retries: 0 | |
| }, | |
| states: { | |
| readOnlyView: { | |
| on: { | |
| START: "readyToScan", | |
| SCAN: "scanFinished" | |
| } | |
| }, | |
| readyToScan: { | |
| on: { | |
| SCAN: "scanFinished", | |
| "": [{ target: "complete", cond: "isComplete" }] | |
| } | |
| }, | |
| scanFinished: { | |
| on: { | |
| "": [ | |
| { target: "itemScanned", cond: "isItemCode" }, | |
| { target: "unknownItem", cond: "alwaysTrue" } | |
| ] | |
| } | |
| }, | |
| unknownItem: { | |
| on: { | |
| SCAN: "scanFinished", | |
| CLOSE: "readyToScan" | |
| } | |
| }, | |
| itemScanned: { | |
| on: { | |
| "": [ | |
| { target: "itemCounter", cond: "needMoreItems" }, | |
| { target: "itemComplete", cond: "isItemComplete" }, | |
| { target: "itemBadCount", cond: "hasBadCount" } | |
| ] | |
| } | |
| }, | |
| itemCounter: { | |
| on: { | |
| PLUS: "itemCounter", | |
| MINUS: "itemCounter" | |
| } | |
| }, | |
| itemComplete: { | |
| on: { | |
| SKIP_DELAY: "readyToScan" | |
| }, | |
| after: { | |
| 1000: "readyToScan" | |
| } | |
| }, | |
| itemBadCount: { | |
| on: { | |
| CLOSE: "readyToScan" | |
| } | |
| }, | |
| complete: { | |
| type: "final" | |
| } | |
| } | |
| }, | |
| { | |
| guards: { | |
| isComplete: (context, event) => false, | |
| isItemCode: (context, event) => true, | |
| alwaysTrue: () => true, | |
| needMoreItems: (context, event) => false, | |
| isItemComplete: (context, event) => true, | |
| hasBadCount: (context, event) => false | |
| } | |
| } | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment