ballmer-peak: use composition instead of mutable state
Alexey Raspopov committed
Oct 12, 2014 at 16:05 UTC
cc0e7d2a79c12c516368e14aacff3cc71d8e3868
1 file changed
+5
-6
examples/ballmer-peak/example.js
+5
-6
@@ -10,6 +10,10 @@ function computeBallmerPeak(x) {
10
) / 1.6;
11
}
12
13
+function percentage(x) {
14
+ return isNaN(x) ? 'N/A' : (100 - Math.round(pct * 100)) + '%';
15
+}
16
+
17
var BallmerPeakCalculator = React.createClass({
18
getInitialState: function() {
19
return {bac: 0};
@@ -18,12 +22,7 @@ var BallmerPeakCalculator = React.createClass({
22
this.setState({bac: event.target.value});
23
},
24
render: function() {
21
- var pct = computeBallmerPeak(this.state.bac);
22
- if (isNaN(pct)) {
23
- pct = 'N/A';
24
- } else {
25
- pct = (100 - Math.round(pct * 100)) + '%';
26
- }
25
+ var pct = percentage(computeBallmerPeak(this.state.bac));
26
return (
27
<div>
28
<img src="./ballmer_peak.png" />