Skip to content

Instantly share code, notes, and snippets.

@kelchm
Created May 20, 2020 15:24
Show Gist options
  • Save kelchm/ed6ccbd191be003087abecff5230ea99 to your computer and use it in GitHub Desktop.
Save kelchm/ed6ccbd191be003087abecff5230ea99 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
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