Skip to content

Instantly share code, notes, and snippets.

@jinnkhan88
Created June 6, 2021 19:25
Show Gist options
  • Save jinnkhan88/d67df5fdce0228725c6b4b686e6a5965 to your computer and use it in GitHub Desktop.
Save jinnkhan88/d67df5fdce0228725c6b4b686e6a5965 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
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