Created
November 4, 2019 19:34
-
-
Save parties/ab052f1186730c080005e55cd8aaf97f to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains hidden or 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
// 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