Skip to content

Instantly share code, notes, and snippets.

@pke
Created January 31, 2020 00:35
Show Gist options
  • Save pke/45ae9b5b16cba060dd590460e00a10fb to your computer and use it in GitHub Desktop.
Save pke/45ae9b5b16cba060dd590460e00a10fb to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const setStatus = assign((context, event, meta) => ({
statusCode: meta.statusCode,
statusText: meta.statusText,
}))
const fetchMachine = Machine({
id: 'http-request',
initial: 'start',
context: {
statusCode: 0,
statusText: "",
},
states: {
start: {
on: {
'': [
{
target: "503",
cond: 'is_service_available',
},
],
},
},
"503": {
type: "final",
},
success: {
entry: {
action: 'setStatus',
meta: {
statusCode: 200,
statusText: "OK" ,
},
},
type: 'final'
},
}
}, {
guards: {
is_service_available: (context) => true,
},
actions: {
setStatus
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment