Skip to content

Instantly share code, notes, and snippets.

@bjorntheart
Created April 30, 2021 10:40
Show Gist options
  • Select an option

  • Save bjorntheart/10d397bf6289653ca75c9e0fd5c4193c to your computer and use it in GitHub Desktop.

Select an option

Save bjorntheart/10d397bf6289653ca75c9e0fd5c4193c 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 quoteMachine = Machine(
{
id: 'quote',
initial: 'idle',
context: {
quote: "",
},
states: {
idle: {
on: {
FETCH: {
target: "loading"
}
}
},
loading: {
invoke: {
id: 'fetchQuote',
src: (context, event) => fetchQuote(context.formData),
onDone: {
target: 'success',
actions: assign({ quote: (context, event) => event.data })
},
onError: {
target: 'failure',
actions: assign({ error: (context, event) => event.data })
}
}
},
success: {},
failure: {
on: {
RETRY: 'loading'
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment