DEV Community

Discussion on: How To Create a Music Player in Reason With The useContext Hook Part 3

Collapse
 
yawaramin profile image
Yawar Amin • Edited

Very cool, great to see this progressing. playTrack can be a little more concise:

let playTrack = index =>
  dispatch(switch (playing) {
    | Playing(idx) when index === idx => MusicPlayer.PauseTrack
    | _ => MusicPlayer.PlayTrack(index)
  });

This captures the fact that we pause only when the current index is playing, and play otherwise; and that we need to dispatch from both branches.