Created
October 20, 2016 02:10
-
-
Save haywoood/096f8657306a86832e6df1109a0211ce to your computer and use it in GitHub Desktop.
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
// Translation of the clock example on http://reagent-project.github.io/ | |
import {state, ui, render} from "essence" | |
const timerState = state({ | |
value: new Date(), | |
color: "#f34" | |
}) | |
setInterval(() => timerState.value = new Date(), 1000) | |
const Greeting = props => <h1>{props.children}</h1> | |
const Clock = ui(() => { | |
const timeStr = timerState.value.toTimeString().split(" ")[0] | |
return ( | |
<div className="example-clock" style={{color: timerState.color}}> | |
{timeStr} | |
</div> | |
) | |
}) | |
const ColorInput = ui(() => ( | |
<div className="color-input"> | |
Time color: <input type="text" value={timerState.color} | |
onChange={(e) => timerState.color = e.target.value} /> | |
</div> | |
)) | |
const SimpleExample = () => ( | |
<div> | |
<Greeting>Hello world, it is now</Greeting> | |
<Clock /> | |
<ColorInput /> | |
</div> | |
) | |
render(<SimpleExample />, "root") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment