Skip to content

Instantly share code, notes, and snippets.

@leobauza
Last active April 8, 2019 02:36
Show Gist options
  • Save leobauza/b040c848e1db24e5fa22c0c887b0a783 to your computer and use it in GitHub Desktop.
Save leobauza/b040c848e1db24e5fa22c0c887b0a783 to your computer and use it in GitHub Desktop.
Traffic Light
Traffic Light
Power On*
power loss -> Power Off
Green*
tick -> Yellow
Yellow
tick -> Red
Red
tick -> Green
Power Off
power restored -> Power On
Red On*
tick -> Red Off
Red Off
tick -> Red On
class Comp extends React.Component {
constructor(props) {
super(props)
console.log('hi')
}
render() {
return <h1>HI!</h1>
}
}
const Light = (props) => {
var styles = {
width: '20px',
height: '20px',
borderRadius: '10px',
marginBottom: '2px',
backgroundColor: props.color,
opacity: .25
};
if(props.isOn){
styles.opacity = 1;
}
return (
<div style={styles}></div>
)
}
const render = (model) => {
var active_light = model.active_states[0].name;
return (
<div>
<Light color="Red" isOn={active_light === "Red" || active_light === "Red On"} />
<Light color="Yellow" isOn={active_light === "Yellow"} />
<Light color="Green" isOn={active_light === "Green"} />
<button type="button" onClick={() => model.emit('tick')}>Tick</button>
</div>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment