Skip to content

Instantly share code, notes, and snippets.

@peterlazar1993
Last active January 4, 2022 07:27
Show Gist options
  • Save peterlazar1993/6c83b77b4697b04e72631f1c85d7c94f to your computer and use it in GitHub Desktop.
Save peterlazar1993/6c83b77b4697b04e72631f1c85d7c94f to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
const fetchMachine = Machine({
id: "checkOTAUpdate",
initial: "CHECKING",
states: {
CHECKING: {
on: {
OTA_CHECK_SUCCESSFUL: [
{target:'UPDATE_AVAILABLE', cond:'isUpdateAvailable'
},
{target:'ON_LATEST_VERSION'}
],
OTA_CHECK_FAILED: 'CHECK_FAILED'
}
},
CHECK_FAILED: {},
UPDATE_AVAILABLE: {
initial: "IDLE",
states: {
IDLE:{
on:{
DOWNLOAD_OTA: "DOWNLOADING"
}
},
DOWNLOADING: {
on: {
OTA_DOWNLOAD_SUCCESS: "DOWNLOADED",
OTA_DOWNLOAD_FAILED: "DOWNLOAD_FAILED",
},
},
DOWNLOADED: {type: 'final'},
DOWNLOAD_FAILED: {},
},
},
ON_LATEST_VERSION: {type: 'final'},
},
}, {
guards: {
isUpdateAvailable: (_, event) => {
return event.isUpdateAvailable
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment