Created
June 6, 2021 19:25
-
-
Save jinnkhan88/d67df5fdce0228725c6b4b686e6a5965 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 lightMachine = Machine({ | |
id:'trafficLight', | |
initial:'red', | |
context:{ | |
rushHourMultiplier:1 | |
}, | |
on:{ | |
INC_RUSH_HOUR:{ | |
actions:['incRushHour'] | |
} | |
}, | |
states:{ | |
green:{ | |
after:{ | |
GREEN_TIMER:'yellow', | |
} | |
}, | |
yellow:{ | |
after:{ | |
YELLOW_TIMER:'red' | |
} | |
}, | |
red:{ | |
after:{ | |
RED_TIMER:'green' | |
} | |
} | |
} | |
}, | |
{ | |
actions:{ | |
incRushHour:assign({ | |
rushHourMultiplier: ctx => ctx.rushHourMultiplier + 1 | |
}) | |
}, | |
delays:{ | |
GREEN_TIMER:ctx => ctx.rushHourMultiplier * 3000, | |
YELLOW_TIMER:ctx => ctx.rushHourMultiplier * 1000, | |
RED_TIMER:ctx => ctx.rushHourMultiplier * 4000 | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment