loading...

Discussion on: State machine advent: Guard state transitions, guard actions (14/24)

Collapse
karfau profile image
Christian Bewernitz

I think I do understand your goal of demonstrating features of XState, but I think there is an issue with your (mental?) model of a thermostat.

For a functioning thermostat there need to be two values related to temperature:

  • the one requested by the user
  • the one measured

Although they would ideally be very close to each other, the whole purpose of the device is to male that happen, since they aren't naturally.

This post is the first one where you mix these two perspectives on temperature into a single field.

An example: Would I be able to turn it off if I set the temperature to 25 °C even if the current temperature in the room is 5 °C?

Collapse
codingdive profile image
Mikey Stengel Author

Thank you for the comment. To keep the examples as simple as possible, they are indeed a bit contrived and do not represent a fully working thermostat in real life. I am indeed mixing the concept of a thermostat tracking the temperature and the temperature that is set by a user according to the explanation at hand. I'm sorry if this made the example more confusing. I did however give a hint to this inconsistency in the 13th post when I showed how context changes are driven by events from a component.

  return (
    <Sensor onChange={(e: {temperature: number }) => void send({ type: 
      SET_TEMPERATURE, temperature: e.temperature }) } />
  )

// or we let the user drive our context changes
  return (
    <input onChange={e => void send({ type: SET_TEMPERATURE, temperature: 
       e.target.value })} placeholder="Set the temperature." />
   )
Collapse
karfau profile image
Christian Bewernitz

I was indeed not aware oft the "Sensor" part, THX for the reply