Skip to content

Commit

Permalink
Address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
mcsf committed Feb 9, 2018
1 parent 039596b commit 8728a64
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions components/higher-order/with-safe-timeout/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* External dependencies
*/
import { without } from 'lodash';

/**
* WordPress dependencies
*/
Expand All @@ -23,7 +28,6 @@ function withSafeTimeout( OriginalComponent ) {
this.timeouts = [];
this.setTimeout = this.setTimeout.bind( this );
this.clearTimeout = this.clearTimeout.bind( this );
this.clear = this.clear.bind( this );
}

componentWillUnmount() {
Expand All @@ -33,19 +37,15 @@ function withSafeTimeout( OriginalComponent ) {
setTimeout( fn, delay ) {
const id = setTimeout( () => {
fn();
this.clear( id );
this.clearTimeout( id );
}, delay );
this.timeouts.push( id );
return id;
}

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

clear( id ) {
this.timeouts = this.timeouts.filter( t => t !== id );
this.timeouts = without( this.timeouts, id );
}

render() {
Expand Down

0 comments on commit 8728a64

Please sign in to comment.