Last active
February 7, 2020 00:06
-
-
Save devstojko/c67b44c4604b6c5b400ac93ea97d9564 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 fetchLocations = () => {} | |
| const mapMachine = Machine({ | |
| id: 'mapMachine', | |
| initial: 'idle', | |
| context: { | |
| locations: undefined, | |
| searchLocations: undefined, | |
| from: '', | |
| to: '', | |
| }, | |
| states: { | |
| idle: { | |
| on: { | |
| FETCH: 'loading' | |
| } | |
| }, | |
| search: { | |
| invoke: { | |
| } | |
| }, | |
| loading: { | |
| invoke: { | |
| id: 'dataLoader', | |
| src: (ctx, e) => fetchLocations(), | |
| onDone: { | |
| target: 'ready', | |
| actions: assign({ | |
| locations: (ctx, e) => e.data | |
| }) | |
| }, | |
| onError: { | |
| target: 'failure', | |
| actions: assign({ | |
| error: (ctx, e) => e.data | |
| }) | |
| } | |
| } | |
| }, | |
| ready: { | |
| initial: 'select', | |
| states: { | |
| select: { | |
| on: { | |
| SELECT_FROM: { | |
| target: '#mapMachine.search', | |
| actions: assign({ | |
| from: (ctx, e) => e.data | |
| }) | |
| }, | |
| SELECT_TO: '#mapMachine.search', | |
| SELECT_DATE: '#mapMachine.search', | |
| SELECT_COUNTER: '#mapMachine.search' | |
| }, | |
| } | |
| } | |
| }, | |
| failure: { | |
| on: { | |
| RETRY: 'loading' | |
| } | |
| } | |
| } | |
| }); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment