Created
January 31, 2020 00:35
-
-
Save pke/45ae9b5b16cba060dd590460e00a10fb to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains hidden or 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 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