-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathserver.html
54 lines (44 loc) · 1.13 KB
/
server.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<div id="app"></div>
</body>
<script>
function createDOM(document) {
return ['div', 'span', 'label', 'p', 'h1', 'input', 'button', 'form'].reduce(function(DOM, tag) {
DOM[tag] = function(attrs, children) {
var elem = document.createElement(tag)
elem = Object.assign(elem, attrs)
if (typeof children === 'string') {
elem.appendChild(document.createTextNode(children))
} else {
children = children || []
children.forEach(function(child) {
var child = typeof child === 'string' ? document.createTextNode(child) : child
elem.appendChild(child)
})
return elem
}
}
return DOM
}, {})
}
var DOM = createDOM(document)
function renderDOM(DOM, elem, fel) {
elem.innerHTML = ''
elem.appendChild(DOM)
}
var initialState = {
text: 'Hello world na klientovi!!'
}
function renderApp(state) {
return DOM.h1({}, [state.text])
}
// tohle do server.js nekopčit!
renderDOM(renderApp(initialState), document.getElementById('app'))
</script>
</html>