Created
January 23, 2021 20:52
-
-
Save raphaelbadia/8dd4aedcdd145b7d563906a26408bccf 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
// Available variables: | |
// - Machine | |
// - interpret | |
// - assign | |
// - send | |
// - sendParent | |
// - spawn | |
// - raise | |
// - actions | |
// - XState (all XState exports) | |
const fetchMachine = Machine({ | |
id: "dog fetcher", | |
initial: "idle", | |
context: { | |
dog: null, | |
error: null | |
}, | |
states: { | |
idle: { | |
on: { FETCH: "loading" } | |
}, | |
loading: { | |
invoke: { | |
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