Created
May 8, 2021 11:38
-
-
Save oliverturner/1e106dd856d252b77607fcbf4ebc1ff1 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) | |
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