Skip to content

Instantly share code, notes, and snippets.

@ShMcK
Last active July 17, 2018 03:02
Show Gist options
  • Save ShMcK/c4527f4a3549ed3434abe2d0bce68a1d to your computer and use it in GitHub Desktop.
Save ShMcK/c4527f4a3549ed3434abe2d0bce68a1d to your computer and use it in GitHub Desktop.
VisualizingState: Walkman State Machine Guard 2
class Walkman extends React.Component {
 transition = (event) => {
  const preventTapeJam = /* ... */
  const shouldEject = event === 'STOP' && this.state.current === 'Stopped'
 
  if (!preventTapeJam) {
  /* … */
  } else if (shouldEject) {
  this.setState({ current: events.EJECT })
  }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment