Skip to content

Instantly share code, notes, and snippets.

@raphaelbadia
Last active January 23, 2021 21:28
Show Gist options
  • Save raphaelbadia/36d7c667b181882ec85a8f9aa5a7ba29 to your computer and use it in GitHub Desktop.
Save raphaelbadia/36d7c667b181882ec85a8f9aa5a7ba29 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
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