Created
July 15, 2020 03:25
-
-
Save simontegg/ae79d618288e8fcb3b501cdb4edc4948 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
| function submitWizard(context) { | |
| return new Promise((resolve, reject) => { | |
| setTimeOut(() => { | |
| const isSuccess = Math.random() > 0 | |
| return isSuccess ? resolve({ data: { your: "result" } }) : reject(Error('did not work')) | |
| }, 3000) | |
| }) | |
| } | |
| const wizard = Machine({ | |
| id: "wizard", | |
| initial: "idle", | |
| context: { | |
| }, | |
| states: { | |
| idle: { id: 'idle', on: { START: "step1" } }, | |
| step1: { | |
| on: { NEXT: "step2" } | |
| }, | |
| step2: { | |
| on: { | |
| PREVIOUS: "step1", | |
| NEXT: "step3" | |
| } | |
| }, | |
| step3: { | |
| on: { | |
| PREVIOUS: "step2", | |
| NEXT: "step4" | |
| } | |
| }, | |
| step4: { | |
| initial: "review", | |
| states: { | |
| review: { | |
| on: { FINISH: "submitting" } | |
| }, | |
| submitting: { | |
| invoke: { | |
| id: "submit-wizard", | |
| src: submitWizard, | |
| onDone: "submitted", | |
| onError: "failed" | |
| } | |
| }, | |
| submitted: { on: { CLOSE: "#idle" } }, | |
| failed: { on: { RETRY: "submitting" } } | |
| }, | |
| }, | |
| }, | |
| }) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment