Skip to content

Instantly share code, notes, and snippets.

@parties
Created November 4, 2019 19:34
Show Gist options
  • Save parties/ab052f1186730c080005e55cd8aaf97f to your computer and use it in GitHub Desktop.
Save parties/ab052f1186730c080005e55cd8aaf97f to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// https://xstate.js.org/viz/?gist=ab052f1186730c080005e55cd8aaf97f
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
const checkoutMachine = Machine(
{
id: "checkout",
initial: "plan",
context: {
totalDue: 0,
balanceDue: 0,
paymentMethods: {},
},
states: {
// * plan tender methods
plan: {
on: {
ADD_PAYMENT_METHOD: {
target: "plan",
},
UPDATE_PAYMENT_METHOD: {
target: "plan",
},
REMOVE_PAYMENT_METHOD: {
target: "plan",
},
TENDER_START: "#checkout.pending",
},
},
// * processing payment for all tender options
pending: {
on: {
RESOLVE: "success",
REJECT: "error",
}
},
voiding: {
on: {
RESOLVE: "voided",
REJECT: "error"
}
},
// * one or more payment options failed
error: {
on: {
TENDER_START: "pending",
VOID_TRANSACTION: "voiding",
}
},
// * all payment methods were successfully processed; final state
success: {
type: "final",
},
voided: {
type: "final"
}
},
},
{},);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment