Created
January 20, 2018 15:03
-
-
Save noeljackson/6fcc43e4d76b1d93c78b46199f5a4c31 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
React.createClass({ | |
// ... | |
onClicked() { | |
// Array of debounced click events | |
this.debouncedClickEvents = this.debouncedClickEvents || []; | |
// Each click we store a debounce (a future execution scheduled in 250 milliseconds) | |
const callback = _.debounce(_ => { | |
// YOUR ON CLICKED CODE | |
this.debouncedClickEvents = []; | |
}, 500); | |
this.debouncedClickEvents.push(callback); | |
// We call the callback, which has been debounced (delayed) | |
callback(); | |
}, | |
onDoubleClicked() { | |
// If there were click events registered we cancel them | |
if (this.debouncedClickEvents.length > 0) { | |
_.map(this.debouncedClickEvents, (debounce) => debounce.cancel()); | |
this.debouncedClickEvents = []; | |
} | |
// YOUR DOUBLE CLICK CODE | |
}, | |
// ... | |
render() { | |
const table = this.props.table; | |
let tableStyle = this.getStyles(); | |
return ( | |
<li onClick={this.onClicked} onDoubleClick={this.onDoubleClicked}> | |
Click me | |
</li> | |
); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment