Skip to content

Commit

Permalink
Add clearInterval to counter component's unmount method.
Browse files Browse the repository at this point in the history
This was added to take fix the case where a user starts a game
and immediately logs out, so the normal cleanup flow doesnt happen properly.
This manually kills the interval when the counterPage gets unmounted.
Adds to fix for #118.
francesar committed Jul 3, 2019
1 parent 62e1a4e commit 847fc2f
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/counterPage.js
Original file line number Diff line number Diff line change
@@ -41,6 +41,12 @@ class Counter extends React.Component {
this.setBaseTime()
}

componentWillUnmount() {
// Make sure to clear counter here in case normal game over flow does
// not happen, ex. the user starts a game and then immediately logs out.
clearInterval(this.intervalHandle);
}

calculateIncrement = () => {
var newIncrement=0;
var difficulty=this.props.baseDifficulty
@@ -115,7 +121,7 @@ class Counter extends React.Component {
}


if (min === 0 & sec === 0) {
if (min === 0 && sec === 0) {
clearInterval(this.intervalHandle);
this.setState({threeCount:1,twoCount:1})
this.props.userFinished()

0 comments on commit 847fc2f

Please sign in to comment.