Skip to content

Instantly share code, notes, and snippets.

@apnerve
Last active December 7, 2019 11:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apnerve/e5a5970cda8acda9045d354f9671125d to your computer and use it in GitHub Desktop.
Save apnerve/e5a5970cda8acda9045d354f9671125d to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const loanMachine = Machine({
id: 'loan',
initial: 'PAYMENT_DETAILS',
context: {
cosigners: 0,
awesome: false,
},
states: {
PAYMENT_DETAILS: {
on: {
submit: 'ENGINE',
},
},
ENGINE: {
on: {
awesome: {
target: 'OFFER_DETAILS',
actions: assign({ awesome: ctx => (ctx.awesome = true) }),
},
hmm: {
target: 'COSIGNER_DETAILS',
cond: "isAwesome",
},
sucks: {
target: 'REJECTED',
cond: "isAwesome",
},
cosigner_sucks: {
cond: ctx => ctx.cosigners > 0,
},
},
},
REJECTED: { type: 'final' },
OFFER_DETAILS: {
on: {
accept_offer: 'ADDRESS_DETAILS',
add_cosigner: {
target: 'COSIGNER_DETAILS',
cond: ctx => ctx.cosigners < 2,
},
},
},
COSIGNER_DETAILS: {
on: {
submit: {
target: 'ENGINE',
actions: assign({ cosigners: ctx => ctx.cosigners + 1 }),
},
},
},
ADDRESS_DETAILS: { type: 'final' },
},
});
function isAwesome(context,event) {
return true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment