Skip to content

Commit

Permalink
When receiving an update to crouton via props, clear ttd before updat…
Browse files Browse the repository at this point in the history
…ing state so that the old timeout that we lose reference to won't dismiss our new message early.
  • Loading branch information
thjelm committed May 21, 2015
1 parent 55d2ea4 commit 372b39a
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,22 @@ module.exports = React.createClass({
if (typeof message === 'string')
message = [message];
var autoMiss = nextProps.autoMiss ? (buttons ? false : true) : nextProps.autoMiss;
this.setState({
hidden: nextProps.hidden,
buttons: buttons,
message: message,
type: nextProps.type
});
if (autoMiss && !nextProps.hidden) {
var ttd = setTimeout(this.dismiss, nextProps.timeout || this.props.timeout);
this.dismiss();
this.setState({
ttd: ttd,
hidden: nextProps.hidden,
buttons: buttons,
message: message,
type: nextProps.type
});
} else {
this.setState({
ttd: ttd
hidden: nextProps.hidden,
buttons: buttons,
message: message,
type: nextProps.type
});
}
},
Expand Down

0 comments on commit 372b39a

Please sign in to comment.