Created
May 9, 2020 02:55
-
-
Save basanth-ivoyant/e79e1c8446d707cf1e19edd7c0259974 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
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