Skip to content

Instantly share code, notes, and snippets.

@Emerson
Last active July 6, 2021 16:46
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 Emerson/677d8792acd52c45e206a890483af005 to your computer and use it in GitHub Desktop.
Save Emerson/677d8792acd52c45e206a890483af005 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 executedPageWizard = Machine({
id: 'executed-page-wizard',
initial: 'lost-pages',
context: {
lostPages: [{}],
unsortedPages: [{}],
},
states: {
'lost-pages': {
on: {
'': [
{target: 'select-file', cond: 'hasNoLostPages'}
],
SKIP: 'select-file',
SORT_LOST_PAGES: 'assign-pages.select-item',
}
},
'select-file': {
on: {
SELECT_FILE: 'select-pages'
}
},
'select-pages': {
on: {
SELECT_PAGES: 'assign-pages.select-item',
BACK: 'select-file'
}
},
'assign-pages': {
states: {
'select-item': {
on: {
SELECT_ITEM: 'select-page',
BACK: '#executed-page-wizard.select-pages'
}
},
'select-page': {
on: {
SELECT_PAGE: 'select-signatures',
SKIP_PAGE: [
{target: 'select-item', cond: 'hasUnsortedPages'},
{target: '#executed-page-wizard.success'}
],
DELETE_PAGE: [
{target: 'select-item', cond: 'hasUnsortedPages'},
{target: '#executed-page-wizard.success'}
]
}
},
'select-signatures': {
on: {
SELECT_SIGNATURES: [
{ target: 'select-item', cond: 'hasUnsortedPages'},
{ target: '#executed-page-wizard.success'}
]
}
}
}
},
success: {
type: 'final'
}
}
}, {
guards: {
hasNoLostPages: function(context) {
return context.lostPages.length === 0
},
hasUnsortedPages: function(context) {
return context.unsortedPages.length > 0;
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment