Last active
October 20, 2015 17:52
-
-
Save derencius/9e57b03623c96ff8a639 to your computer and use it in GitHub Desktop.
coffee script vs es6
This file contains hidden or 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
import React from 'react'; | |
import _ from 'underscore'; | |
class Sensor extends React.Component { | |
cssClass() { | |
if (this.props.toggled) { | |
return 'on'; | |
} | |
else { | |
return 'off'; | |
} | |
} | |
render() { | |
return <span className={this.cssClass() + " glyphicon " + this.props.icon} title={this.props.name}>Sensors</span>; | |
} | |
} | |
export default class Sensors extends React.Component { | |
render() { | |
return ( | |
<span className='sensors'> | |
{_.map(this.props.sensors, (sensor, index) => | |
<Sensor key={index} name={sensor[0]} toggled={sensor[1]} icon={this.props.icon}></Sensor> | |
)} | |
</span> | |
) | |
} | |
} |
This file contains hidden or 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
{span} = React.DOM | |
SensorComponent = React.createClass | |
displayName: 'Sensor' | |
cssClass: -> | |
if @props.toggled | |
'on' | |
else | |
'off' | |
render: -> | |
span className: "#{@cssClass()} glyphicon #{@props.icon}", title: @props.name, '' | |
@sensorComponent = React.createFactory(SensorComponent) | |
SensorsComponent = React.createClass | |
displayName: 'Sensors' | |
render: -> | |
span key: 'sensors', className: 'sensors', | |
for sensor, i in @props.sensors | |
sensorComponent | |
key: "sensor#{i}" | |
name: sensor[0] | |
toggled: sensor[1] | |
icon: @props.icon | |
@sensorsComponent = React.createFactory(SensorsComponent) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment