Skip to content

Instantly share code, notes, and snippets.

@oliverturner
Created May 8, 2021 11:38
Show Gist options
  • Save oliverturner/1e106dd856d252b77607fcbf4ebc1ff1 to your computer and use it in GitHub Desktop.
Save oliverturner/1e106dd856d252b77607fcbf4ebc1ff1 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)
function assignDataToContext(){}
function assignErrorMessageToContext(){}
function fetchRowOfData(){
send({ type: "receivedData", data: {} });
}
function thereIsMoreData(){
return true
}
function thereIsNoMoreData(){
return true
}
function clearErrorMessage(){}
const fetchMachine = Machine({
initial: 'fetchingRowOfData',
states: {
fetchingRowOfData: {
on: {
receivedData: {
target: 'checkMoreDataExists',
actions: [assignDataToContext]
},
invoke: {
src: fetchRowOfData,
onError: {
target: 'idle',
actions: [assignErrorMessageToContext]
}
}
}
},
checkMoreDataExists: {
always: [
{
target: 'idle',
cond: thereIsMoreData
}, {
target: 'noMoreDataToFetch',
cond: thereIsNoMoreData
}
]
},
idle: {
exit: [clearErrorMessage],
on: {
scrollToBottom: 'fetchingRowOfData'
}
},
noMoreDataToFetch: {
type: 'final'
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment