Last active
July 10, 2021 08:07
-
-
Save socheatsok78/9365acbe248d6f694a2d8897b5dc0368 to your computer and use it in GitHub Desktop.
Traffic Light - XState Example
This file contains hidden or 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 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