Only update upcoming date once the current upcoming date has ran out.

feature/webpack
Icedream 2017-08-26 00:43:21 +02:00
parent d7a42d03f7
commit c32db349d9
Signed by: icedream
GPG Key ID: 1573F6D8EFE4D0CF
1 changed files with 14 additions and 1 deletions

View File

@ -45,6 +45,7 @@ class App extends React.Component {
componentWillUnmount() {
clearInterval(this.interval);
this.interval = null;
}
calculateUpcomingDate() {
@ -56,7 +57,19 @@ class App extends React.Component {
}
updateUpcomingDate() {
this.setState({ nextUpcomingDate: this.calculateUpcomingDate() });
const { getNow } = this.props;
const nextUpcomingDate = this.calculateUpcomingDate();
if (this.interval) {
const interval = moment.duration(nextUpcomingDate.diff(getNow()))
.asMilliseconds();
clearInterval(this.interval);
this.interval = setInterval(this.updateUpcomingDate.bind(this), interval);
}
this.setState({ nextUpcomingDate });
}
render() {