Skip to content

Instantly share code, notes, and snippets.

@jeremy-green
Created September 13, 2019 12:05
Show Gist options
  • Save jeremy-green/ce5ca6a27de6a57d0705ce3059bdd0a3 to your computer and use it in GitHub Desktop.
Save jeremy-green/ce5ca6a27de6a57d0705ce3059bdd0a3 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
new Machine({
id: 'ABCDE1234567',
type: 'parallel',
context: {
battery: null,
},
states: {
status: {
id: `status-ABCDE1234567`,
initial: 'idle',
states: {
idle: {
on: {
INIT: 'ready',
},
},
ready: {
entry() {
console.log('ready');
},
on: {
CLEAN: 'begin',
CHARGE: 'end',
},
},
begin: {
entry: ({ battery }) => {
console.log('begin', battery);
if (battery <= 0.2) {
console.log('low battery');
}
},
on: {
CHARGE: 'end',
BROKEN: 'reattempt',
},
},
end: {
entry: () => {
console.log('end');
// this.#vacbot.run('charge');
},
on: {
CLEAN: 'begin',
},
},
reattempt: {
entry: () => {
console.log('reattempt:entry');
},
on: {
CHARGE: 'end',
},
},
},
},
battery: {
id: `battery-ABCDE1234567`,
initial: 'idle',
states: {
idle: {
on: {
INIT: 'monitor',
},
},
refresh: {
on: {
'': {
target: 'monitor',
},
},
},
monitor: {
entry: () => {
console.log('monitor:entry');
},
invoke: {
src: (context, event) => new Promise((resolve, reject) => setTimeout(() => resolve(), 2500)),
onDone: {
target: 'refresh',
actions: [
assign({ battery: (context, { data }) => data }),
({ battery }) => console.log('monitor:onDone', battery),
],
},
},
},
},
},
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment