Skip to content

Instantly share code, notes, and snippets.

@joaom182
Created November 9, 2021 22:00
Show Gist options
  • Save joaom182/74e58d5e3e9beb94c22cef422b89f900 to your computer and use it in GitHub Desktop.
Save joaom182/74e58d5e3e9beb94c22cef422b89f900 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
const fetchMachine = Machine({
id: 'services-and-provision',
initial: 'init',
states: {
init: {
always: [
{
target: 'select-entities',
cond: 'lastEventIsNext'
},
{
target: 'answer-questions',
actions: ['assignLastEntity'],
cond: 'lastEntityNeedsAnswerQuestions'
},
{
target: 'provide-documents',
actions: ['assignLastEntity'],
cond: 'lastEntityNeedsProvideDocuments'
},
{
target: 'select-services',
actions: ['assignLastEntity'],
cond: 'lastEntityIsApplyingForServices'
}
]
},
'select-entities': {
on: {
NEXT: [
{
target: 'select-services',
actions: ['assignNextEntity'],
cond: 'nextEntityIsApplyingForServices'
},
{
target: 'provide-documents',
actions: ['assignNextEntity'],
cond: 'nextEntityNeedsProvideDocuments'
},
{
target: 'answer-questions',
actions: ['assignNextEntity'],
cond: 'nextEntityNeedsAnswerQuestions'
},
{
target: 'provide-documents',
actions: ['assignNextEntityThatNeedsProvideDocuments'],
cond: 'hasSomeNextEntityToProvideDocument'
},
{
target: 'answer-questions',
actions: ['assignNextEntityThatNeedsAnswerQuestions'],
cond: 'hasSomeNextEntityToAnswerQuestions'
},
{
target: 'success'
}
]
}
},
'select-services': {
entry: ['assignCurrentEntityFromQueryString', 'clearCurrentEntityCards'],
on: {
NEXT: [
{
target: 'provide-documents',
cond: 'currentEntityNeedsProvideDocuments'
},
{
target: 'answer-questions',
cond: 'currentEntityNeedsAnswerQuestions'
},
{
target: 'select-services',
actions: ['assignNextEntity'],
cond: 'nextEntityIsApplyingForServices'
},
{
target: 'provide-documents',
actions: ['assignNextEntity'],
cond: 'nextEntityNeedsProvideDocuments'
},
{
target: 'answer-questions',
actions: ['assignNextEntity'],
cond: 'nextEntityNeedsAnswerQuestions'
},
{
target: 'provide-documents',
actions: ['assignNextEntityThatNeedsProvideDocuments'],
cond: 'hasSomeNextEntityToProvideDocument'
},
{
target: 'answer-questions',
actions: ['assignNextEntityThatNeedsAnswerQuestions'],
cond: 'hasSomeNextEntityToAnswerQuestions'
},
{
target: 'success'
}
],
BACK: [
{
target: 'answer-questions',
actions: ['assignPreviousEntity'],
cond: 'previousEntityNeedsAnswerQuestions'
},
{
target: 'provide-documents',
actions: ['assignPreviousEntity'],
cond: 'previousEntityNeedsProvideDocuments'
},
{
target: 'select-services',
actions: ['assignPreviousEntity'],
cond: 'previousEntityIsApplyingForServices'
},
{
target: 'select-entities',
actions: ['clearCurrentEntity']
}
]
}
},
'provide-documents': {
entry: ['assignCurrentEntityFromQueryString', 'clearCurrentEntityCards'],
on: {
NEXT: [
{
target: 'answer-questions',
cond: 'currentEntityNeedsAnswerQuestions'
},
{
target: 'select-services',
actions: ['assignNextEntity'],
cond: 'nextEntityIsApplyingForServices'
},
{
target: 'provide-documents',
actions: ['assignNextEntity'],
cond: 'nextEntityNeedsProvideDocuments'
},
{
target: 'answer-questions',
actions: ['assignNextEntity'],
cond: 'nextEntityNeedsAnswerQuestions'
},
{
target: 'provide-documents',
actions: ['assignNextEntityThatNeedsProvideDocuments'],
cond: 'hasSomeNextEntityToProvideDocument'
},
{
target: 'answer-questions',
actions: ['assignNextEntityThatNeedsAnswerQuestions'],
cond: 'hasSomeNextEntityToAnswerQuestions'
},
{
target: 'success'
}
],
BACK: [
{
target: 'select-services',
cond: 'currentEntityIsApplyingForServices'
},
{
target: 'answer-questions',
actions: ['assignPreviousEntity'],
cond: 'previousEntityNeedsAnswerQuestions'
},
{
target: 'provide-documents',
actions: ['assignPreviousEntity'],
cond: 'previousEntityNeedsProvideDocuments'
},
{
target: 'select-services',
actions: ['assignPreviousEntity'],
cond: 'previousEntityIsApplyingForServices'
},
{
target: 'answer-questions',
actions: ['assignPreviousEntityThatNeedsAnswerQuestions'],
cond: 'hasSomePreviousEntityToAnswerQuestions'
},
{
target: 'provide-documents',
actions: ['assignPreviousEntityThatNeedsProvideDocuments'],
cond: 'hasSomePreviousEntityToProvideDocument'
},
{
target: 'select-entities',
actions: ['clearCurrentEntity']
}
]
}
},
'answer-questions': {
entry: ['assignCurrentEntityFromQueryString', 'clearCurrentEntityCards'],
on: {
NEXT: [
{
target: 'success',
cond: 'currentEntityIsTheLastEntity'
},
{
target: 'select-services',
actions: ['assignNextEntity'],
cond: 'nextEntityIsApplyingForServices'
},
{
target: 'provide-documents',
actions: ['assignNextEntity'],
cond: 'nextEntityNeedsProvideDocuments'
},
{
target: 'answer-questions',
actions: ['assignNextEntity'],
cond: 'nextEntityNeedsAnswerQuestions'
},
{
target: 'provide-documents',
actions: ['assignNextEntityThatNeedsProvideDocuments'],
cond: 'hasSomeNextEntityToProvideDocument'
},
{
target: 'answer-questions',
actions: ['assingNextEntityThatNeedsAnswerQuestions'],
cond: 'hasSomeNextEntityToAnswerQuestions'
},
{
target: 'success'
}
],
BACK: [
{
target: 'provide-documents',
cond: 'currentEntityNeedsProvideDocuments'
},
{
target: 'select-services',
cond: 'currentEntityIsApplyingForServices'
},
{
target: 'answer-questions',
actions: ['assignPreviousEntity'],
cond: 'previousEntityNeedsAnswerQuestions'
},
{
target: 'provide-documents',
actions: ['assignPreviousEntity'],
cond: 'previousEntityNeedsProvideDocuments'
},
{
target: 'answer-questions',
actions: ['assignPreviousEntityThatNeedsAnswerQuestions'],
cond: 'hasSomePreviousEntityToAnswerQuestions'
},
{
target: 'provide-documents',
actions: ['assignPreviousEntityThatNeedsProvideDocuments'],
cond: 'hasSomePreviousEntityToProvideDocument'
},
{
target: 'select-entities',
actions: ['clearCurrentEntity']
}
]
}
},
success: {
type: 'final'
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment