ballmer-peak: use composition instead of mutable state

This commit is contained in:
Alexey Raspopov committed 2014-10-12 16:05:58 +03:00
1 parent 5d3b12bb3b
commit cc0e7d2a79
1 file changed
+5 -6
+5 -6
View File
@@ -10,6 +10,10 @@ function computeBallmerPeak(x) {
) / 1.6;
}
function percentage(x) {
return isNaN(x) ? 'N/A' : (100 - Math.round(pct * 100)) + '%';
}
var BallmerPeakCalculator = React.createClass({
getInitialState: function() {
return {bac: 0};
@@ -18,12 +22,7 @@ var BallmerPeakCalculator = React.createClass({
this.setState({bac: event.target.value});
},
render: function() {
var pct = computeBallmerPeak(this.state.bac);
if (isNaN(pct)) {
pct = 'N/A';
} else {
pct = (100 - Math.round(pct * 100)) + '%';
}
var pct = percentage(computeBallmerPeak(this.state.bac));
return (
<div>
<img src="./ballmer_peak.png" />