Created
November 23, 2020 19:32
-
-
Save cmd-save/0f5f98f5d9a76d47ab7d016c6f70febf 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: 'search', | |
| initial: 'idle', | |
| context: { | |
| result: {}, | |
| totalCount: 0 | |
| }, | |
| on: { | |
| SEARCH: [ | |
| { | |
| target: 'searching', | |
| cond: { | |
| type: 'search query has more than one character' | |
| } | |
| }, | |
| { | |
| target: 'idle', | |
| actions: ['resetSearchResult'] | |
| } | |
| ] | |
| }, | |
| states: { | |
| idle: {}, | |
| searching: { | |
| invoke: { | |
| id: 'searchService', | |
| src: 'searchService', | |
| onDone: { | |
| target: 'loaded', | |
| actions: ['storeResult'] | |
| }, | |
| onError: { | |
| target: 'failure', | |
| actions: assign({ | |
| error: (_, e)=>console.log('onError', e.data) | |
| }) | |
| } | |
| } | |
| }, | |
| loaded: {}, | |
| failure: {} | |
| } | |
| }); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment