Last active
July 17, 2018 02:54
-
-
Save ShMcK/36bc8f4fcc8f563398d1d59f68c958d3 to your computer and use it in GitHub Desktop.
VisualizingState: Walkman State Machine + Complexity
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 { | |
state = { | |
current: events.STOP, | |
} | |
transition = (event) => { | |
this.setState({ current: events[event] }) | |
} | |
render() { | |
const Button = ({ children, event, active }) => { | |
return ( | |
<button onClick={() => this.transition(event)}> | |
{children} | |
</button> | |
) | |
} | |
return ( | |
<div> | |
<div>{this.state.current}</div> | |
<Button event='STOP'>◼</Button> | |
<Button event='PLAY'>►</Button> | |
<Button event='REWIND'>◀◀</Button> | |
<Button event='FAST_FORWARD'>▶▶</Button> | |
</div> | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment