-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommits.html
More file actions
73 lines (61 loc) · 1.8 KB
/
commits.html
File metadata and controls
73 lines (61 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
<title>Commits</title>
<script src="https://unpkg.com/react@latest/dist/react.js"></script>
<script src="https://unpkg.com/react-dom@latest/dist/react-dom.js"></script>
<script src="https://unpkg.com/babel-standalone@6.15.0/babel.min.js"></script>
</head>
<body>
<div id="root"></div>
<script type="text/babel">
class Commits extends React.Component {
constructor(props) {
super(props);
this.state = {value: '...'};
this.initialize();
}
initialize() {
var that = this;
fetch(this.props.url)
.then(function(data) {
Promise.resolve(data.text()).then(function(v) {
that.setState({value: v});
});
})
.catch(function() {
that.setState({value: 'boo'});
});
}
render() {
return <div>Commits for {this.props.url} resulted in {this.state.value} when <Timer/></div>;
}
}
class Timer extends React.Component {
constructor(props) {
super(props);
this.state = {secondsElapsed: 0};
}
tick() {
this.setState((prevState) => ({
secondsElapsed: prevState.secondsElapsed + 1
}));
}
componentDidMount() {
this.interval = setInterval(() => this.tick(), 1000);
}
componentWillUnmount() {
clearInterval(this.interval);
}
render() {
return (
<span>Seconds Elapsed: {this.state.secondsElapsed}</span>
);
}
}
var root = document.getElementById('root');
ReactDOM.render(<Commits url="https://api.github.com/repos/ivanmoore/Eatcheap/commits" />, root);
</script>
</body>
</html>