Created
November 16, 2014 15:13
-
-
Save srph/fcd27d3e87a483b26ee9 to your computer and use it in GitHub Desktop.
[ReactJS] basic countdown mechanics (https://gist.github.com/srph/fcd27d3e87a483b26ee9)
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
var CountdownControl = React.createClass({ | |
// Simplified for brevity | |
render: function() { | |
var control = this.props.status | |
? 'Pause' | |
: 'Resume'; | |
return ( | |
<span onClick={this._handleClick}> | |
{control} | | |
</span> | |
); | |
}, | |
_handleClick: function() { | |
// Toggle interval (clear or set) based on this.props.status | |
} | |
}); |
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
var CountdownTimer = React.createClass({ | |
// Simplified for brevity | |
_setInterval: function() { | |
/* this.interval = setInterval.... | |
* call setTick as callback for setInterval | |
*/ | |
}, | |
_clearInterval: function() { /* this.interval = clearInterval.. */ }, | |
_setTick: function() { /* run tick */ }, | |
render: function() { | |
return ( | |
<CountdownControl | |
status={this.interval} | |
pause={this._setInterval} | |
resume={this._clearInterval} /> | |
{this.state.elapsed} seconds has elapsed | |
); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment