Last active
May 29, 2020 13:08
-
-
Save joernroeder/605c8cf168a43af5a5fd2c7f0cf0c526 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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