Skip to content

Commit

Permalink
Introduce restart behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
madzzie committed Oct 14, 2018
1 parent d297c3b commit 51c0058
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/Metronome.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,21 @@ class Metronome extends Component {

handleBpmChange = event => {
const bpm = event.target.value;
this.setState({bpm});

if (this.state.playing) {
// Stop the old timer and start a new one
clearInterval(this.timer);
this.timer = setInterval(this.playClick, (60 / bpm) * 1000);

// Set the new BPM, and reset the beat counter
this.setState({
count: 0,
bpm
});
} else {
// Otherwise just update the BPM
this.setState({bpm});
}
};

playClick = () => {
Expand Down

0 comments on commit 51c0058

Please sign in to comment.