Skip to content

Instantly share code, notes, and snippets.

@orther
Last active May 8, 2021 06:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save orther/f098f6a6aeebe415623d9b608d698029 to your computer and use it in GitHub Desktop.
Save orther/f098f6a6aeebe415623d9b608d698029 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 updateDeviceMachine = Machine({
id: 'updateDevice',
initial: 'idle',
context: {
retries: 0,
lastHexRecordNumber: null,
},
states: {
idle: {
on: {
DO_CONNECT: 'connecting'
}
},
connecting: {
id: 'connectingBleDevice',
invoke: () => {
const hold = new Promise()
// connecting
return hold
},
onDone: {
target: 'detectingDeviceMode',
},
onError: {
target: 'failure',
},
after: {
10000: 'failure'
}
},
detectingDeviceMode: {
on: {
READ_JSON: [
{
target: 'monitoringMainApp',
cond: 'isMainApp'
/*
(ctx, e) => {
return isMainApp
}
*/
},
{
target: 'monitoringBootloader',
cond: 'isBootloader',
/*
cond: (ctx, e) => {
return isBootloader
}
*/
}
]
},
after: {
10000: 'failure'
}
},
monitoringMainApp: {
},
monitoringBootloader: {
},
failure: {
// on: {
// RETRY: {
// target: 'loading',
// actions: assign({
// retries: (context, event) => context.retries + 1
// })
// }
// }
}
},
guards: {
isMainApp: () => {
return true
},
isBootloader: () => {
return true
},
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment