Created
April 30, 2021 10:40
-
-
Save bjorntheart/10d397bf6289653ca75c9e0fd5c4193c 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 quoteMachine = Machine( | |
| { | |
| id: 'quote', | |
| initial: 'idle', | |
| context: { | |
| quote: "", | |
| }, | |
| states: { | |
| idle: { | |
| on: { | |
| FETCH: { | |
| target: "loading" | |
| } | |
| } | |
| }, | |
| loading: { | |
| invoke: { | |
| id: 'fetchQuote', | |
| src: (context, event) => fetchQuote(context.formData), | |
| onDone: { | |
| target: 'success', | |
| actions: assign({ quote: (context, event) => event.data }) | |
| }, | |
| onError: { | |
| target: 'failure', | |
| actions: assign({ error: (context, event) => event.data }) | |
| } | |
| } | |
| }, | |
| success: {}, | |
| failure: { | |
| on: { | |
| RETRY: 'loading' | |
| } | |
| } | |
| } | |
| }); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment