Last active
September 2, 2020 18:22
-
-
Save jmegs/61ca6ca85f46cb677d7a4b36246d9297 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains 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
// 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