Skip to content

Instantly share code, notes, and snippets.

@jmegs
Last active September 2, 2020 18:22
Show Gist options
  • Save jmegs/61ca6ca85f46cb677d7a4b36246d9297 to your computer and use it in GitHub Desktop.
Save jmegs/61ca6ca85f46cb677d7a4b36246d9297 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: 'check_card',
initial: 'idle',
states: {
idle: {
on: {
CHECK: {
target: "fetching",
actions: ['send_check']
}
}
},
fetching: {
on: {
RESOLVE: "success",
REJECT: "failure"
},
after: {250: "waiting"}
},
waiting: {
on: {
RESOLVE: "success",
REJECT: "failure"
},
after: {5000: "failure"}
},
failure: {
on: { RETRY: {
target:"fetching",
actions: ["send_check"]
} }
},
success: {}
},
actions: {
send_check: (context, event) => {
console.log("telling the server the card is checked")
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment