Skip to content

Instantly share code, notes, and snippets.

@joernroeder
Last active May 29, 2020 13:08
Show Gist options
  • Save joernroeder/605c8cf168a43af5a5fd2c7f0cf0c526 to your computer and use it in GitHub Desktop.
Save joernroeder/605c8cf168a43af5a5fd2c7f0cf0c526 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: 'ConfirmAndExecuteMachine',
initial: 'idle',
context: {
data: undefined,
errorMessage: '',
hasLoaded: false, // initial flag
isLoading: false, // loading indicator per request,
lastUpdate: undefined
},
states: {
idle: {
id: 'idle',
on: {
CONFIRM: 'confirm'
}
},
confirm: {
id: 'confirm',
initial: 'showConfirm',
states: {
showConfirm: {
on: {
CANCEL: '#idle',
SUBMIT: 'execute'
}
},
execute: {
initial: 'executing',
states: {
executing: {
entry: ['startLoading'],
exit: ['hasLoaded', 'stopLoading'],
invoke: {
src: 'execute',
onDone: { target: 'success', actions: ['setData', 'clearError'] },
onError: { target: 'failure', actions: ['setErrorMessage', 'clearData'] }
}
},
failure: {
after: {
2000: '#idle'
}
},
success: {
after: {
2000: '#idle'
}
}
}
}
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment