Last active
July 18, 2018 02:12
-
-
Save ShMcK/ea1759a06d75dd89e83670eaee906b5a to your computer and use it in GitHub Desktop.
Visualizing State: Walkman State Machine Guard
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 events = { | |
STOP: 'Stopped', | |
PLAY: 'Playing', | |
REWIND: 'Rewinding', | |
FASTFORWARD: 'FastForwarding', | |
} | |
class Walkman extends React.Component { | |
transition = (target) => { | |
const preventTapeJam = | |
['REWIND', 'FASTFORWARD', 'PLAY'].includes(target) && | |
this.state.current === 'stopped' | |
if (!preventTapeJam) { | |
this.setState({ current: events[target] }) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment