Skip to content

Commit

Permalink
#484 less code dublication
Browse files Browse the repository at this point in the history
  • Loading branch information
Norman Eremic committed Jul 21, 2016
1 parent 77c27d4 commit 5b125e3
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions client/lib/yourturn/src/notification-bar/notification-bar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,7 @@ class NotificationBar extends React.Component {
const { notifications = [] } = nextProps;

if (!this.state.interval && notifications.length > 0) {
let interval = setInterval(() => {
this.props.dispatch(Actions.removeNotificationsOlderThan(5000));
}, 5000);
this.setState({
interval
});
this.startInterval();
} else if (this.state.interval && notifications.length == 0) {
clearInterval(this.state.interval);
this.setState({
Expand All @@ -59,15 +54,22 @@ class NotificationBar extends React.Component {
*/
const { notifications = [] } = this.props;
if (notifications.length > 0) {
let interval = setInterval(() => {
this.props.dispatch(Actions.removeNotificationsOlderThan(5000));
}, 5000);
this.startInterval();
this.setState({
interval
});
}
}

startInterval() {
let interval = setInterval(() => {
this.props.dispatch(Actions.removeNotificationsOlderThan(5000));
}, 5000);
this.setState({
interval
});
}

componentWillUnmount() {
clearInterval(this.state.interval);
}
Expand Down

0 comments on commit 5b125e3

Please sign in to comment.