Last active
January 23, 2021 21:28
-
-
Save raphaelbadia/36d7c667b181882ec85a8f9aa5a7ba29 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains 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
const fetchRandomDog = () => null | |
const specialitySelectMachine = Machine({ | |
id: "dog fetcher", | |
initial: "loading", | |
context: { | |
dog: null, | |
error: null | |
}, | |
states: { | |
idle: { | |
on: { FETCH: "loading" } | |
}, | |
loading: { | |
invoke: { | |
id: 'fetch random dog', | |
src: () => fetchRandomDog(), | |
onDone: { | |
target: "success", | |
actions: assign({ dog: (_, event) => event.data.message }) | |
}, | |
onError: { | |
target: "failure", | |
actions: assign({ error: (_, event) => event.data }) | |
} | |
}, | |
on: { CANCEL: "idle" } | |
}, | |
success: { | |
on: { FETCH: "loading" } | |
}, | |
failure: { | |
on: { FETCH: "loading" } | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment