Skip to content

Instantly share code, notes, and snippets.

@colebemis
Last active March 25, 2020 09:51
Show Gist options
  • Save colebemis/14a92f4d3b3f89d27a23f969615a480a to your computer and use it in GitHub Desktop.
Save colebemis/14a92f4d3b3f89d27a23f969615a480a 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)
// selectionEmptyBranchExistingEmpty
// selectionValidBranchNewEmpty
// vs. emptySelectionEmptyExistingBranch
const fetchMachine = Machine({
id: 'fetch',
initial: 'selectionEmptyBranchNewEmpty',
context: {
commitMessage: '',
defaultCommitMessage: '',
newBranchName: '',
existingBranchName: '',
svgFiles: [],
error: ''
},
on: {
CHANGE_COMMIT_MESSAGE: {
actions: 'setCommitMessage'
}
},
states: {
selectionEmptyBranchNewEmpty: {
on: {
CHANGE_SELECTION: 'selectionValidBranchNewEmpty',
CHANGE_NEW_BRANCH_NAME:
'selectionEmptyBranchNew',
SWITCH_TO_EXISTING_BRANCH: [
{
target: 'selectionEmptyBranchExistingEmpty',
cond: 'isExistingBranchNameEmpty'
},
{
target: 'selectionEmptyBranchExisting'
}
]
}
},
selectionEmptyBranchNew: {
on: {
CHANGE_SELECTION: 'selectionValidBranchNew',
CHANGE_NEW_BRANCH_NAME: [
{
target: 'selectionEmptyBranchNewEmpty',
cond: 'isNewBranchNameEmpty',
actions: 'setNewBranchName'
},
{ action: 'setNewBranchName' }
]
}
},
selectionEmptyBranchExistingEmpty: {
on: {
CHANGE_SELECTION:
'selectionValidBranchExistingEmpty',
CHANGE_EXISTING_BRANCH_NAME: [
{
target: 'selectionEmptyBranchExistingEmpty',
cond: 'isExistingBranchNameEmpty',
actions: 'setExistingBranchName'
},
{ actions: 'setExistingBranchName' }
]
}
},
selectionEmptyBranchExisting: {
on: {
SELECTION_CHANGE:
'selectionValidBranchExisting'
}
},
selectionValidBranchNewEmpty: {
on: {
NEW_BRANCH_NAME_CHANGE: 'selectionValidBranchNew'
}
},
selectionValidBranchNew: {
on: {
SUBMIT: 'submittingBranchNew'
}
},
selectionValidBranchExistingEmpty: {},
selectionValidBranchExisting: {
on: {
SUBMIT: 'submittingBranchExisting'
}
},
selectionInvalidBranchNewEmpty: {
on: {
SELECTION_CHANGE: [
{target: 'selectionValidBranchNewEmpty', cond: 'isSelectionValid'},
{target: 'selectionEmptyBranchNewEmpty', cond: 'isSelectionEmpty'}]
}
},
selectionInvalidBranchNew: {},
selectionInvalidBranchExistingEmpty: {},
selectionInvalidBranchExisting: {},
submittingBranchNew: {
on: {
SUCCESS: 'successBranchNew'
}
},
submittingBranchExisting: {
on: {
SUCCESS: 'selectionEmptyBranchExisting'
}
},
successBranchNew: {
on: {
DONE: 'selectionEmptyBranchExisting'
}
},
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment