-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
154 lines (145 loc) · 4.63 KB
/
index.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Troll Hunter App</title>
</head>
<body>
<!--
<div id="app">
<template th-component="HelloWorld"></template>
<template th-component="HelloWorld"></template>
<template th-component="HelloWorld"></template>
<p> Lorem ipsum dolor sit amet consectetur adipisicing elit. Quibusdam, repudiandae commodi totam officia illo, reprehenderit magni laboriosam est aspernatur autem, culpa ducimus! Sed soluta nemo maiores quae at facere explicabo? </p>
<h3>Jobs</h3>
<ul loop="jobs" template="jobCard"></ul>
<button on="click mouseover" action="show changeBg">Show</button>
<button on="click" action="add">Add</button>
<button on="click" action="subtract">Subtract</button>
<div var="counter" if="showCounter">Counter</div>
<template th-component="ColorTextClicker"></template>
</div>
-->
<template th-component="ToDoList"></template>
<script src="/index.js"></script>
<script>
/**let state = {
name:"Troll Hunter App",
counter:0,
jobs:["programmer","developer","project manager","software engineer"],
showCounter:true,
bgColor:"red",
}
let actions = {
add(){
state.counter++;
state.updateState("counter",state.counter);
},
subtract(){
state.counter--;
state.updateState("counter",state.counter);
},
show(){
state.showCounter = !state.showCounter;
state.updateState("showCounter",state.showCounter)
},
changeBg(){
if(state.bgColor == 'red'){
state.bgColor = 'green';
}else{
state.bgColor = "red"
}
state.updateState("bgColor",state.bgColor);
document.body.style.backgroundColor = state.bgColor
}
}
let templates = {
jobCard:function(value,index){
return `
<li>${value}</li>
`
},
}
let app = new TrollHunter(state);
app.setActions(actions);
app.setTemplates(templates);
state.updateState("jobs",["programmer","developer","project manager",])
app.init();
TrollHunter.createComponent(
{
name:"HelloWorld",
parentEl:"nav",
data:{
message:"Hello World"
},
template:function(state){
return `
<h1>${state.message}</h1>
`
},
}
)
TrollHunter.createComponent(
{
name:"ColorTextClicker",
parentEl:"div",
data:{
counter:true
},
template:function(state){
return `
<button on="click" action="counter">Component Button</button>
<p>Counter State <span var="counter"></span> </p>
`
},
actions:{
counter(){
this.data.counter = !this.data.counter
this.data.updateState("counter",this.data.counter)
}
}
}
)
TrollHunter.start()
**/</script>
<script>
TrollHunter.createComponent({
name:"ToDoItem",
parentEl:"li",
data:{
text:""
},
template(data){
return `
${data.text}
`
}
})
TrollHunter.createComponent({
name:"ToDoList",
parentEl:"ul",
data:{
list:['java',"c#","js","lua"]
},
actions:{
addItem(){
this.data.updateState("list",[...this.data.list,"TrollHUnter","Server"])
}
},
template(data){
return `
${data.list.map(item=>{
return `
<template th-component="ToDoItem" text="${item}"></template>
`
}).join("")}
<button on="click" action="addItem" >Add</button>
`
}
})
TrollHunter.start();
</script>
</body>
</html>