Skip to content

Commit

Permalink
Clear timeout when unmounting.
Browse files Browse the repository at this point in the history
This caused an exception when the tooltip was removed from the dom
before it was scheduled to show up.
  • Loading branch information
joelburget committed Jan 20, 2016
1 parent b4c38df commit 1ff68f4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
5 changes: 3 additions & 2 deletions dist/react-tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ var ReactTooltip = (function (_Component) {
window.removeEventListener('__react_tooltip_hide_event', this.globalHide);
window.removeEventListener('__react_tooltip_rebuild_event', this.globalRebuild);
window.removeEventListener('resize', this.onWindowResize);
window.clearTimeout(this.delayShowLoop);
};

/* TODO: optimize, bind has been trigger too maany times */
Expand Down Expand Up @@ -337,7 +338,7 @@ var ReactTooltip = (function (_Component) {
var delayShow = _state.delayShow;
var show = _state.show;

clearTimeout(this.delayShowLoop);
window.clearTimeout(this.delayShowLoop);

var delayTime = show ? 0 : parseInt(delayShow, 10);
var eventTarget = e.currentTarget;
Expand Down Expand Up @@ -374,7 +375,7 @@ var ReactTooltip = (function (_Component) {

var delayHide = this.state.delayHide;

clearTimeout(this.delayShowLoop);
window.clearTimeout(this.delayShowLoop);
setTimeout(function () {
_this3.setState({
show: false
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
},
"dependencies": {
"classnames": "^1.2.0",
"react-dom": "^0.14.0"
"react-dom": "0.14.*"
},
"devDependencies": {
"babel": "^5.3.1",
Expand Down
5 changes: 3 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export default class ReactTooltip extends Component {
window.removeEventListener('__react_tooltip_hide_event', this.globalHide)
window.removeEventListener('__react_tooltip_rebuild_event', this.globalRebuild)
window.removeEventListener('resize', this.onWindowResize)
window.clearTimeout(this.delayShowLoop)
}

/* TODO: optimize, bind has been trigger too maany times */
Expand Down Expand Up @@ -277,7 +278,7 @@ export default class ReactTooltip extends Component {
*/
updateTooltip (e) {
const {delayShow, show} = this.state
clearTimeout(this.delayShowLoop)
window.clearTimeout(this.delayShowLoop)

const delayTime = show ? 0 : parseInt(delayShow, 10)
const eventTarget = e.currentTarget
Expand Down Expand Up @@ -306,7 +307,7 @@ export default class ReactTooltip extends Component {
*/
hideTooltip () {
const {delayHide} = this.state
clearTimeout(this.delayShowLoop)
window.clearTimeout(this.delayShowLoop)
setTimeout(() => {
this.setState({
show: false
Expand Down

0 comments on commit 1ff68f4

Please sign in to comment.