Last active
May 8, 2021 06:58
-
-
Save orther/f098f6a6aeebe415623d9b608d698029 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains 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
// 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