Skip to content

Instantly share code, notes, and snippets.

@basanth-ivoyant
Created May 9, 2020 02:55
Show Gist options
  • Save basanth-ivoyant/e79e1c8446d707cf1e19edd7c0259974 to your computer and use it in GitHub Desktop.
Save basanth-ivoyant/e79e1c8446d707cf1e19edd7c0259974 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const fetchMachine = Machine({
id: 'initialLoad',
initial: 'start',
context: {
config:[
"a", "b"
]
},
states: {
start:{
on:{
'FETCH_CONFIG': {
target:'fetchConfig'
}
}
},
fetchConfig: {
invoke:{
id:'config',
src:'callApis',
onDone: {
target: 'fetchData',
actions : 'saveData'
},
onError: {
target: 'fetchConfigFailure'
}
}
},
fetchData: {
invoke:{
id: 'data',
src: 'callApis',
onDone: {
target: 'complete',
actions : 'saveData'
},
onError: {
fetch: 'fetchDataFailure'
}
}
},
complete: {
type: 'final'
},
fetchConfigFailure:{
type: 'final'
},
fetchDataFailure: {
type: 'final'
}
}
}, {
services: {
callApis:(context,event) => {
console.log(event);
console.log(context);
return Promise.resolve(event.type);
}
},
actions: {
saveData:(context,event) => {
console.log('Save response from ',event.data);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment