Created
December 4, 2020 14:30
-
-
Save lbineau/420938c1beb2880cb2a23fe586ff3a99 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
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