Created
July 4, 2020 14:40
-
-
Save LevelbossMike/1b7e330cb49ccc3367b293651fa89377 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 notifyActionName(context, event) { | |
| window.alert(`Triggered action \`${event.type}\``) | |
| } | |
| const fetchMachine = Machine( { | |
| id: 'quickstart-button-step-8', | |
| context: { | |
| disabled: false | |
| }, | |
| type: 'parallel', | |
| states: { | |
| interactivity: { | |
| initial: 'unknown', | |
| states: { | |
| unknown: { | |
| on: { | |
| '': [{ target: 'enabled', cond: 'isEnabled' }, { target: 'disabled' }], | |
| }, | |
| }, | |
| enabled: { | |
| on: { | |
| DISABLE: 'disabled', | |
| }, | |
| }, | |
| disabled: { | |
| on: { | |
| ENABLE: 'enabled', | |
| }, | |
| }, | |
| }, | |
| }, | |
| activity: { | |
| initial: 'idle', | |
| states: { | |
| idle: { | |
| on: { | |
| SUBMIT: { | |
| target: 'busy', | |
| cond: 'isEnabled', | |
| }, | |
| }, | |
| }, | |
| busy: { | |
| entry: ['handleSubmit'], | |
| on: { | |
| SUCCESS: 'success', | |
| ERROR: 'error', | |
| }, | |
| }, | |
| success: { | |
| entry: ['handleSuccess'], | |
| on: { | |
| SUBMIT: { | |
| target: 'busy', | |
| cond: 'isEnabled', | |
| }, | |
| }, | |
| }, | |
| error: { | |
| entry: ['handleError'], | |
| on: { | |
| SUBMIT: { | |
| target: 'busy', | |
| cond: 'isEnabled', | |
| }, | |
| }, | |
| }, | |
| }, | |
| }, | |
| }, | |
| }, | |
| { | |
| actions: { | |
| handleSubmit: notifyActionName, | |
| handleSuccess: notifyActionName, | |
| handleError: notifyActionName, | |
| }, | |
| guards: { | |
| isEnabled(context) { | |
| return !context.disabled; | |
| }, | |
| }, | |
| } | |
| ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment