Last active
August 26, 2017 23:35
-
-
Save rbiggs/a7b6bb07efd91ab103e5d6649ee4dc92 to your computer and use it in GitHub Desktop.
Example of clock with Composi
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
import {h, Component} from 'composi' | |
class Clock extends Component { | |
constructor(props) { | |
super(props) | |
this.state = {time: new Date()}; | |
} | |
render() { | |
return ( | |
<div> | |
<h1>Hello, world!</h1> | |
<h2>It is {this.state.time.toLocaleTimeString()}.</h2> | |
</div> | |
) | |
} | |
componentWasCreated() { | |
this.timerID = setInterval(() => this.tick(), 1000) | |
} | |
componentWillUnmount() { | |
clearInterval(this.timerID) | |
} | |
tick() { | |
this.setState({ | |
time: new Date() | |
}); | |
} | |
} | |
const clock = new Clock({ | |
root: '#clock' | |
}) |
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no"> | |
<meta name="apple-mobile-web-app-capable" content="yes"> | |
<meta name="mobile-web-app-capable" content="yes"> | |
<meta name="msapplication-tap-highlight" content="no"> | |
<title>Clock</title> | |
<link rel="stylesheet" href="./css/chui-ios.css"> | |
<link rel="stylesheet" href="./css/styles.css"> | |
</head> | |
<body> | |
<ui-screen class="current" id="main"> | |
<nav> | |
<h1 style='flex: 1; text-align: left;'>Clock Example</h1> | |
</nav> | |
<section> | |
<p id='clock'></p> | |
</section> | |
</ui-screen> | |
<script src="./js/app.js"></script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment