Skip to content

Instantly share code, notes, and snippets.

@youmustfight
Last active April 30, 2020 14:10
Show Gist options
  • Save youmustfight/7974fcaac6e7cd8ddd5275840cad5dab to your computer and use it in GitHub Desktop.
Save youmustfight/7974fcaac6e7cd8ddd5275840cad5dab to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const screenerMachine = Machine({
id: 'screenerMachine',
initial: 'checkDebtLevels',
states: {
checkDebtLevels: {
on: {
HIGH: 'segueWithTeam',
// https://xstate.js.org/docs/guides/communication.html#invoking-machines
LOW: sendParent('DISQUALIFIED')
}
},
segueWithTeam: {
after: {
3000: 'checkConfidenceLevels'
},
},
checkConfidenceLevels: {
on: {
// Same result, one w/ shorthand
CONFIDENT: 'checkIfWantshelp',
NOT_CONFIDENT: {
target: 'checkIfWantshelp'
},
},
},
checkIfWantshelp: {
type: 'final',
on: {
YES: sendParent('QUALIFIED'),
NO: sendParent('DISQUALIFIED')
}
},
},
});
// In xstate/viz, comment our rest so you can just see the screener
const leadMachine = Machine({
id: 'leadMachine',
initial: 'getName',
states: {
getName: {
on: { ENTERED: 'getPhone' },
},
getPhone: {
on: { ENTERED: 'optIn' },
},
getOptIn: {
on: { ENTERED: 'getPhone' },
},
submitted: {
type: 'final'
}
},
});
const signUpMachine = Machine({
id: 'signUpMachine',
initial: 'upsolveExplanation',
context: {},
states: {
upsolveExplanation: {
on: {
START: 'screener'
}
},
screener: {
// https://xstate.js.org/docs/guides/communication.html#the-invoke-property
// Can invoke machines, or promises!
invoke: {
id: 'screen',
src: screenerMachine,
onDone: 'qualified'
},
on: {
// screenerMachine sends events
QUALIFIED: 'qualified',
DISQUALIFIED: 'disqualified'
},
},
qualified: {
type: 'final'
},
disqualified: {
type: 'final',
invoke: {
id: 'disqualified',
src: leadMachine,
},
},
}
})
@youmustfight
Copy link
Author

image
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment