-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.html
More file actions
50 lines (43 loc) · 1.34 KB
/
example.html
File metadata and controls
50 lines (43 loc) · 1.34 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
<!DOCTYPE html>
<html lang="pt-br" dir="ltr">
<head>
<meta charset="utf-8">
<title>puu.js</title>
<link rel="stylesheet" href="puu.css">
</head>
<body>
<div id="root"></div>
<script type="text/javascript" src="puu.js"></script>
<script>
// inicializar puu.js
const puu = new Puu(document.getElementById('root'));
// criar contextos ( variaveis, funções, etc.)
puu.context({
posts: ['oi', 'test'],
})
puu.context({
listPosts: () => {
const posts = puu.ctx('posts');
let string = ''
for(let x in posts) string = `<p class="post">${posts[x]}</p>` + string
return string
},
newPost: () => document.querySelector('input[name="message"]').value
})
puu.watch({ message: '' })
// chamando e atualizando contexto fora do puujs
const newPost = () => {
puu.context({ posts: [ ... puu.ctx('posts'), puu.ctx('f:newPost')] })
}
// inicializar template
puu.template(`
<h1>puu.js</h1>
<input type="text" name="message" placeholder="No que esta pensando?" puu-watch="message" value="{{w:message}}">
<button onclick="newPost()">Publicar "{{w:message}}"</button>
<div class="posts">
{{f:listPosts}}
</div>
`)
</script>
</body>
</html>