Created
November 13, 2019 13:27
-
-
Save davidkpiano/414c0e4c40dab1dc80c9218f85605a24 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
const dogFetcherMachine = Machine({ | |
id: "dog fetcher", | |
initial: "idle", | |
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