Skip to content

Instantly share code, notes, and snippets.

@raphaelbadia
Created January 23, 2021 20:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raphaelbadia/8dd4aedcdd145b7d563906a26408bccf to your computer and use it in GitHub Desktop.
Save raphaelbadia/8dd4aedcdd145b7d563906a26408bccf to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// 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