-
Notifications
You must be signed in to change notification settings - Fork 0
/
react-stateful-component.html
48 lines (42 loc) · 1.04 KB
/
react-stateful-component.html
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
<!doctype html>
<html><head>
<meta charset="utf-8" />
<title>React Stateful Component in duil</title>
</head>
<body>
<div>
<a href="https://github.com/metaist/duil.js/blob/master/tutorials/react-stateful-component.html">view code</a>
(<a href="https://reactjs.org/">original</a>)
<hr />
</div>
<div id="root">
</div>
<script src="https://cdn.jsdelivr.net/npm/jquery@3.2.1/dist/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/duil/dist/duil.min.js"></script>
<script>
const Timer = new duil.Widget({
$dom: $('#root'),
interval: false,
seconds: 0,
// @override
init: function () {
this.interval = window.setInterval(() => this.tick(), 1000);
return this;
},
// never actually called
destroy: function () {
window.clearInterval(this.interval);
return this;
},
tick: function () {
this.set({seconds: this.seconds + 1});
return this;
},
// @override
render: function () {
this.$dom.text(`Seconds: ${this.seconds}`)
return this;
}
});
</script>
</body></html>