Last active
October 21, 2020 14:42
-
-
Save LevelbossMike/b90b7a517f8f756d2c87dce240f102fd 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 noop() {} | |
| const async = Machine( | |
| { | |
| id: 'async', | |
| initial: "idle", | |
| context: { | |
| trigger: noop, | |
| onSuccess: noop, | |
| onError: noop | |
| }, | |
| states: { | |
| idle: { | |
| on: { | |
| DO: "busy" | |
| } | |
| }, | |
| busy: { | |
| invoke: { | |
| id: "async", | |
| src: (context) => context.trigger, | |
| onDone: { | |
| target: "success" | |
| }, | |
| onError: { | |
| target: "error" | |
| } | |
| } | |
| }, | |
| success: { | |
| entry: "handleSuccess", | |
| on: { | |
| DO: "busy" | |
| } | |
| }, | |
| error: { | |
| entry: "handleError", | |
| on: { | |
| DO: "busy" | |
| } | |
| } | |
| } | |
| }, | |
| { | |
| actions: { | |
| handleSuccess(context, event) { | |
| const { data } = event; | |
| context.onSuccess(data); | |
| }, | |
| handleError(context, event) { | |
| const { data } = event; | |
| context.onError(data); | |
| } | |
| } | |
| } | |
| ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment