Skip to content

Instantly share code, notes, and snippets.

@lbineau
Created December 4, 2020 14:30
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 lbineau/420938c1beb2880cb2a23fe586ff3a99 to your computer and use it in GitHub Desktop.
Save lbineau/420938c1beb2880cb2a23fe586ff3a99 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const isGasable = (context) => context.temperature >= 100
const isFreezable = (context) => context.temperature < 0
const isLiquidable = (context) => context.temperature > 0 && context.temperature < 100
const waterMachine = Machine({
id: 'waterMachine',
initial: 'ice',
context: {
temperature: 0
},
states: {
ice: {
on: {
FUSION: {target:'liquid', cond: isLiquidable},
SUBLIMATION: {target:'gas', cond: isGasable}
}
},
liquid: {
on: {
SOLIDIFICATION: 'ice',
VAPORISATION: 'gas'
}
},
gas: {
on: {
CONDENSATION: 'ice',
LIQUEFACTION: 'liquid'
}
},
},
on: {
INCREASE_ROOM_TEMPERATURE: {
actions: assign({ temperature: (context) => context.temperature + 10 })
},
DECREASE_ROOM_TEMPERATURE: {
actions: assign({ temperature: (context) => context.temperature - 10 })
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment