Skip to content

Instantly share code, notes, and snippets.

@avesus
Last active December 8, 2019 18:15
Show Gist options
  • Save avesus/a397f424aea8ae8ddfa6f439bcc78d13 to your computer and use it in GitHub Desktop.
Save avesus/a397f424aea8ae8ddfa6f439bcc78d13 to your computer and use it in GitHub Desktop.
Experimental Statechart
const deviceMachine = Machine({
id: 'device',
initial: 'powered_off',
states: {
powered_on: {
type: 'parallel',
on: {
OFF: 'powered_off',
},
states: {
fan_machine: {
initial: 'fanOff',
states: {
fanOff: {
on: {
POWER: 'fanOn',
HIGH_POWER: 'fanOn.third'
}
},
fanOn: {
initial: 'first',
states: {
first: {
on: { TIMER: 'second' }
},
second: {
on: { TIMER: 'third' }
},
third: {
on: { TIMER: 'first' }
},
},
on: {
POWER: 'fanOff'
}
}
}
},
traffic_light_working: {
initial: 'green',
states: {
green: {
on: {
TIMER: 'yellow'
}
},
yellow: {
on: {
TIMER: 'red'
}
},
red: {
initial: 'walk',
on: {
TIMER: 'green'
},
states: {
walk: {
on: {
PED_TIMER: 'wait'
}
},
wait: {
on: {
PED_TIMER: 'stop'
}
},
stop: {}
}
}
}
}
}
},
powered_off: {
on: {
ON: 'powered_on'
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment