-
Notifications
You must be signed in to change notification settings - Fork 1
/
todo_app.html
99 lines (62 loc) · 1.94 KB
/
todo_app.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<!DOCTYPE html>
<html>
<body>
</body>
<script type="text/javascript" charset="UTF-8" src="tree.js"></script>
<script type="text/javascript">
function main(){
twig({
name: "inputBox",
keypress:function(event){
var tmp = this.parent.state.value
if (event.key == 'Enter'){
tmp.push(event.target.value)
this.parent.setState({value:tmp})
event.target.value = ''
}
},
ui:function(){
return $('input', { onkeypress: this.keypress,placeholder: this.placeholder })
}
})
twig({
name:'view',
ge:function(){
let a = []
for(index of this.parent.state.value ){
a.push( $( 'li',{ text:index } ) )
}
return a
},
ui:function(){
return $('ul',{childs:
this.ge()
})
}
})
twig({
name: "counter",
addCount: function(event){
//here this will be redefined
// console.log(this)
// console.log(this.state.count)
this.setState({count: this.state.count+1 })
},
// pb: addCount gets executed on object instantiation
ui:function(){
return $('button', {
text:this.state.count, onClick:this.addCount
})
},
init:function(){
this.state.count = 0
}
})
tree({
state:{ value:[] },
build:[ inputBox({placeholder:'press enter to add'}),view() ]
})
}
//make twigs functions
</script>
</html>