Created
July 11, 2020 15:49
-
-
Save muratbeser/ea0a22b2e9782d6c5fca89adbcdfcebc 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: 'app', | |
| initial: 'initialize', | |
| context: { | |
| modules: [], | |
| menu: [], | |
| message: undefined | |
| }, | |
| states: { | |
| initialize: { | |
| invoke: { | |
| id: 'verifyJWT', | |
| src: async () => { | |
| return false; | |
| }, | |
| onError: { | |
| target: 'failureJWT', | |
| actions: assign({ | |
| errorMessage: (context, event) => { | |
| // event is: | |
| // { type: 'error.execution', data: 'No query specified' } | |
| return event.data; | |
| } | |
| }) | |
| }, | |
| onDone: { | |
| target: 'successJWT', | |
| actions: assign({ modules: (_, event) => event.data }) | |
| } | |
| } | |
| }, | |
| successJWT: { | |
| invoke: { | |
| id: 'loadModules', | |
| src: async () => { | |
| return []; | |
| }, | |
| onError: { | |
| target: 'failureLoadModules', | |
| actions: assign({ | |
| errorMessage: (context, event) => { | |
| // event is: | |
| // { type: 'error.execution', data: 'No query specified' } | |
| return event.data; | |
| } | |
| }) | |
| }, | |
| onDone: { | |
| target: 'successLoadModules', | |
| actions: assign({ modules: (_, event) => event.data }) | |
| } | |
| } | |
| }, | |
| failureJWT: {}, | |
| failureLoadModules: {}, | |
| successLoadModules: {} | |
| } | |
| } | |
| ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment