Skip to content

Instantly share code, notes, and snippets.

@pke
Last active January 31, 2020 00:51
Show Gist options
  • Save pke/b089354814242ea16b3a1705e2dff272 to your computer and use it in GitHub Desktop.
Save pke/b089354814242ea16b3a1705e2dff272 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: {
request: {
uri: "https://localhost",
},
statusCode: 0,
statusText: "",
},
states: {
start: {
on: {
'': [
{
target: "checkUriLength",
cond: 'is_service_available',
},
'503',
],
},
},
checkUriLength: {
on: {
'': [
{
target: "414",
cond: 'is_uri_too_long',
},
'200',
],
},
},
200: {
type: "final",
},
414: {
type: "final",
},
503: {
type: "final",
},
}
}, {
guards: {
is_service_available: (context) => true,
is_uri_too_long: (context) => context.request.uri.length < 2048,
},
actions: {
setStatus
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment