Created
May 20, 2020 15:24
-
-
Save kelchm/ed6ccbd191be003087abecff5230ea99 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
const hasDelinquencies = () => true; | |
const hasInsufficientFunds = () => false; | |
const generateDisqualificationStates = (name, condition) => ({ | |
[name]: { | |
initial: 'evaluating', | |
states: { | |
evaluating: { | |
on: { | |
EVALUATE_DISQUALIFICATION: [ | |
{ | |
target: 'disqualified', | |
cond: condition, | |
}, | |
{ | |
target: 'notDisqualified', | |
}, | |
] | |
}, | |
}, | |
disqualified: { | |
onEntry: send('DISQUALIFIED') | |
}, | |
notDisqualified: {}, | |
} | |
} | |
}); | |
const financialPlanMachine = Machine({ | |
id: 'financialPlan', | |
type: 'parallel', | |
states: { | |
disqualificationReasons: { | |
type: 'parallel', | |
states: { | |
...generateDisqualificationStates('delinquencyThresholdExceeded', hasDelinquencies), | |
...generateDisqualificationStates('insufficientFunds', hasInsufficientFunds), | |
}, | |
on: { | |
USER_INPUT: 'disqualificationReasons', | |
}, | |
}, | |
planType: { | |
initial: 'qualified', | |
states: { | |
qualified: { | |
on: { | |
DISQUALIFIED: 'disqualified' | |
} | |
}, | |
disqualified: {} | |
}, | |
} | |
}, | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment