Permalink
Browse files

Added logic to <ButtonForCounter> to continue counting theoretically …

…up to 40 times per second for as long as the user is pressing the button.
  • Loading branch information...
maratbn committed Jul 2, 2018
1 parent e5ddcfe commit a02cce358f038c6a2ffeaf386c4f8405c254a422
Showing with 30 additions and 3 deletions.
  1. +30 −3 webpack_in/entry.jsx
@@ -233,10 +233,37 @@ class ListWidget extends React.Component {
}
class ButtonForCounter extends React.Component {
constructor(props) {
super(props);
this._onCountStart = () => {
this._flagCount = true;
const doCount = () => {
if (!this._flagCount) {
return;
}
this.props.onCount();
setTimeout(doCount, 25);
};
doCount();
};
this._onCountStop = () => {
this._flagCount = false;
};
}
render() {
return (<button onClick={ () => {
this.props.onCount();
}}>{ this.props.caption }</button>);
return (<button onMouseDown={ this._onCountStart }
onMouseUp={ this._onCountStop }
onMouseLeave={ this._onCountStop }
onTouchStart={ this._onCountStart }
onTouchEnd={ this._onCountStop }
onTouchCancel={ this._onCountStop }>{ this.props.caption }</button>);
}
}

0 comments on commit a02cce3

Please sign in to comment.