Skip to content

Commit

Permalink
Implement feedback
Browse files Browse the repository at this point in the history
- fix typos
- remove `parseInt`
- DRY
  • Loading branch information
Essk committed Sep 29, 2023
1 parent c2599de commit c4aedef
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/js/clickable-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ClickableComponent extends Component {
* A class or space separated list of classes to add the component
*
* @param {number | boolean} [options.throttle]
* A throttle will be applied to the clickHander if the number is >= 1 or the value is `true`
* A throttle will be applied to the clickHandler if the number is >= 1 or the value is `true`
* A number specifies the desired wait time in ms or a default wait of 50ms will be applied
*
*/
Expand All @@ -46,20 +46,22 @@ class ClickableComponent extends Component {
this.controlText(this.options_.controlText);
}

const throttleIsNumber = typeof this.options_.throttle === 'number';
const boundClick = this.handleClick.bind(this);
const selectClickHandler = () => {
if (typeof this.options_.throttle === 'number' || this.options_.throttle === true) {
const wait = typeof this.options_.throttle === 'number' ? parseInt(this.options_.throttle, 10) : 50;
if (throttleIsNumber || this.options_.throttle === true) {
const wait = throttleIsNumber ? this.options_.throttle : 50;

return throttle(this.handleClick.bind(this), wait);
return throttle(boundClick, wait);
}
return this.handleClick.bind(this);
return boundClick;
};

const selectedClickHander = selectClickHandler();
const selectedClickHandler = selectClickHandler();

this.handleMouseOver_ = (e) => this.handleMouseOver(e);
this.handleMouseOut_ = (e) => this.handleMouseOut(e);
this.handleClick_ = (e) => selectedClickHander(e);
this.handleClick_ = (e) => selectedClickHandler(e);
this.handleKeyDown_ = (e) => this.handleKeyDown(e);

this.emitTapEvents();
Expand Down

0 comments on commit c4aedef

Please sign in to comment.