-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathapp.js
50 lines (42 loc) · 1012 Bytes
/
app.js
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
import h from './my-hyperscript.js'
import Component from './component'
import { diff } from './v-dom.js';
const getRandomItemFromArray = (list) => {
return list[
Math.round(Math.random() * (list.length - 1))
];
};
class App extends Component {
render() {
return h('div', { class: 'app' },
h('h1', null, 'Simple vDOM'),
h(People)
)
}
};
class People extends Component {
constructor(props) {
super(props)
this.state = {
list: [
'🕺', '💃', '😀', '🙋', '💼',
'🕶️️', '👏', '🤳', '🕵️', '👩🔧'
]
}
this.timer = setInterval(_ => {
this.setState({
list: [...this.state.list, getRandomItemFromArray(this.state.list)]
})
}, 1000)
}
render(props, state) {
return h(
'ul', null,
...state.list.map(item => h('li', null, item))
)
}
}
const render = (vnode, parent) => {
diff(undefined, vnode, parent)
}
render(h(App), document.querySelector('#root'))