-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
54 lines (41 loc) · 1.53 KB
/
index.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
51
52
53
54
console.log("start----");
import { init } from './patch'
import h from './d2V'
import attr from './modules/attributes'
import nClass from './modules/class'
import props from './modules/props'
import style from './modules/style'
const patch = init([
attr,
nClass, // makes it easy to toggle classes
props, // for setting properties on DOM elements
style, // handles styling on elements with support for animations
])
var someFn = function () {
console.log('someFn', arguments);
}
var anotherEventHandler = function () {
console.log('anotherEventHandler', arguments);
}
var vnode = h('div#container.two.classes', { on: { click: someFn } }, [
h('p', { style: { fontWeight: 'bold' } }, 'This is bold'),
' and this is just normal text',
h('a', { props: { href: '/foo' } }, 'I\'ll take you places!')
]);
console.log('vnode', vnode);
var newVnode = h('div#container.two.classes', { on: { click: anotherEventHandler } }, [
h('span', { style: { fontWeight: 'normal', fontStyle: 'italic' } }, 'This is now italic type'),
' and this is still just normal text',
h('a', { props: { href: '/bar' } }, 'I\'ll take you places!')
]);
console.log('newVnode', newVnode);
function patchNew(vnode, newVnode) {
// Second `patch` invocation
let n = patch(vnode, newVnode); // Snabbdom efficiently updates the old view to the new state
console.log(n)
}
window.addEventListener('DOMContentLoaded', () => {
var container = document.getElementById('container');
vnode = patch(container, vnode);
setTimeout(function () { patchNew(vnode, newVnode) }, 2000);
});