Skip to content

Commit a02cce3

Browse files
committed
Added logic to <ButtonForCounter> to continue counting theoretically up to 40 times per second for as long as the user is pressing the button.
1 parent e5ddcfe commit a02cce3

1 file changed

Lines changed: 30 additions & 3 deletions

File tree

webpack_in/entry.jsx

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,37 @@ class ListWidget extends React.Component {
233233
}
234234

235235
class ButtonForCounter extends React.Component {
236+
constructor(props) {
237+
super(props);
238+
239+
this._onCountStart = () => {
240+
this._flagCount = true;
241+
242+
const doCount = () => {
243+
if (!this._flagCount) {
244+
return;
245+
}
246+
247+
this.props.onCount();
248+
249+
setTimeout(doCount, 25);
250+
};
251+
252+
doCount();
253+
};
254+
255+
this._onCountStop = () => {
256+
this._flagCount = false;
257+
};
258+
}
259+
236260
render() {
237-
return (<button onClick={ () => {
238-
this.props.onCount();
239-
}}>{ this.props.caption }</button>);
261+
return (<button onMouseDown={ this._onCountStart }
262+
onMouseUp={ this._onCountStop }
263+
onMouseLeave={ this._onCountStop }
264+
onTouchStart={ this._onCountStart }
265+
onTouchEnd={ this._onCountStop }
266+
onTouchCancel={ this._onCountStop }>{ this.props.caption }</button>);
240267
}
241268
}
242269

0 commit comments

Comments
 (0)