Skip to content

Instantly share code, notes, and snippets.

@socheatsok78
Last active July 10, 2021 08:07
Show Gist options
  • Save socheatsok78/9365acbe248d6f694a2d8897b5dc0368 to your computer and use it in GitHub Desktop.
Save socheatsok78/9365acbe248d6f694a2d8897b5dc0368 to your computer and use it in GitHub Desktop.
Traffic Light - XState Example
const pedestrianStates = {
initial: 'walk',
states: {
walk: {
on: {
PED_TIMER: 'wait'
}
},
wait: {
on: {
PED_TIMER: 'stop'
}
},
stop: {}
}
};
Machine({
id: 'light',
initial: 'green',
states: {
green: {
on: {
TIMER: 'yellow'
}
},
yellow: {
on: {
TIMER: 'red'
}
},
red: {
on: {
TIMER: 'green'
},
...pedestrianStates
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment