Skip to content

Commit

Permalink
withSafeTimeout: Also provide clearTimeout
Browse files Browse the repository at this point in the history
  • Loading branch information
mcsf committed Feb 5, 2018
1 parent ff410da commit 360a51d
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions components/higher-order/with-safe-timeout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ function withSafeTimeout( OriginalComponent ) {
super( ...arguments );
this.timeouts = [];
this.setTimeout = this.setTimeout.bind( this );
this.clearTimeout = this.clearTimeout.bind( this );
this.clear = this.clear.bind( this );
}

Expand All @@ -38,6 +39,11 @@ function withSafeTimeout( OriginalComponent ) {
return id;
}

clearTimeout( id ) {
clearTimeout( id );
this.clear( id );
}

clear( id ) {
this.timeouts = this.timeouts.filter( t => t !== id );
}
Expand All @@ -47,6 +53,7 @@ function withSafeTimeout( OriginalComponent ) {
<OriginalComponent
{ ...this.props }
setTimeout={ this.setTimeout }
clearTimeout={ this.clearTimeout }
/>
);
}
Expand Down

0 comments on commit 360a51d

Please sign in to comment.