Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 Aug 5, 2018
1 parent e5ddcfe commit a02cce3
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions webpack_in/entry.jsx
Expand Up @@ -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>);
}
}

Expand Down

0 comments on commit a02cce3

Please sign in to comment.