Skip to content

Instantly share code, notes, and snippets.

@tivac
Created October 16, 2019 19:52
Show Gist options
  • Save tivac/f8ec83acba677f5e88bfeda5e7ab39e3 to your computer and use it in GitHub Desktop.
Save tivac/f8ec83acba677f5e88bfeda5e7ab39e3 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const fetchMachine = Machine({
initial: 'run',
context: {},
states: {
run : {
invoke : {
id : "id",
src : () => new Promise((resolve) => {
setTimeout(() => resolve({
value : "VALUE",
}), 1000);
}),
onDone : [
{
target : "complete",
},
{
target : "complete",
actions : assign({
value : (ctx, { data }) => data.value,
connection : (ctx, { data }) => {
data.field = data.value;
return data;
},
}),
},
],
onError : console.error,
},
},
complete : {
type : "final",
},
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment