-
Notifications
You must be signed in to change notification settings - Fork 0
/
react-todo-application.html
71 lines (63 loc) · 1.58 KB
/
react-todo-application.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<!doctype html>
<html><head>
<meta charset="utf-8" />
<title>React ToDo Application in duil</title>
</head>
<body>
<div>
<a href="https://github.com/metaist/duil.js/blob/master/tutorials/react-todo-application.html">view code</a>
(<a href="https://reactjs.org/">original</a>)
<hr />
</div>
<div id="root">
<h3>TODO</h3>
<ul>
<li></li>
</ul>
<form>
<label for="new-todo">
What needs to be done?
</label>
<input id="new-todo" />
<button></button>
</form>
</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 TodoList = new duil.List({$dom: $('#root ul')});
const TodoApp = new duil.Widget({
$dom: $('#root'),
items: [],
text: '',
// @override
init: function () {
this.$dom
.on('change', 'input', this.change)
.on('submit', 'form', this.submit);
return this;
},
// @override
render: function () {
this.$dom
.find('input').val(this.text).end()
.find('button').text('Add #' + (this.items.length + 1)).end();
TodoList.set({data: this.items});
return this;
},
change: function (e) {
this.set({text: e.target.value});
return this;
},
submit: function (e) {
e.preventDefault();
if (!this.text.length) { return; }
var nextItems = this.items.concat([this.text]);
var nextText = '';
this.set({items: nextItems, text: nextText});
this.$dom.find('input').focus();
return false;
}
});
</script>
</body></html>