Skip to content

Instantly share code, notes, and snippets.

@tomByrer
Last active January 16, 2021 21:50
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 tomByrer/9d6e5352666fe9a7011b78d7ea46f644 to your computer and use it in GitHub Desktop.
Save tomByrer/9d6e5352666fe9a7011b78d7ea46f644 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// Master machine for radio buttons
const inputGroupMachine = Machine({
id: 'input-group',
initial: 'emptied',
states: {
emptied: {
on: {
'': {
actions: 'loadNew',
target: 'pending',
},
}
},
pending: {
on: {
REJECT: 'failure',
FULFILL: 'distributing',
}
},
failure: {
on: {
RETRY: 'pending',
}
},
distributing: { // render indivudal items array
on: {
COMPLETE: 'selectable',
// REJECT: 'failure',
}
},
selectable: {
initial: 'empty',
states: {
empty: {
on: {
FILL: 'full',
SKIP: '#skip-current',
}
},
full: {
on: {
FILL: 'full', // EMPTY old item
SKIP: '#skip-current',
SUBMIT: 'submitting',
// SELECT: 'sending'
}
},
submitting: {
on: {
COMPLETE: '#empty-old'
}
},
}
},
skipping: {
id: 'skip-current',
on: {
'': {
actions: 'skipCurrent',
target: 'emptying',
},
}
},
emptying: {
id: 'empty-old',
on: {
'': {
actions: 'emptyOld',
target: 'emptied',
},
}
},
}
},
{
actions: {
emptyOld: (context, event) => {
console.log('loading new group...')
},
loadNew: (context, event) => {
console.log('loading new group...')
},
skipCurrent: (context, event) => {
console.log('skip this...')
},
},
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment