OSDN Git Service

Regular updates
[twpd/master.git] / virtual-dom.md
1 ---
2 title: Virtual-dom
3 category: JavaScript libraries
4 ---
5
6 See <https://www.npmjs.com/package/virtual-dom>
7
8 ```js
9 var h = require('virtual-dom/h')
10 var diff = require('virtual-dom/diff')
11 var patch = require('virtual-dom/patch')
12 var createElement = require('virtual-dom/create-element')
13 ```
14
15 ### Rendering
16
17 ```js
18 tree = h('div', { style: { color: 'blue' } }, [ 'hello' ])
19 el = createElement(tree)
20 document.body.appendChild(root)
21 ```
22
23 ### Updating
24
25 ```js
26 tree2 = h('div', { style: { color: 'blue' } }, [ 'hello world' ])
27 delta = diff(tree, tree2)
28 el = patch(el, delta) // patch() modifies el
29 ```