File tree Expand file tree Collapse file tree
getting-started-with-virtual-dom Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ // var div = document.createElement('div')
2+ // div.innerHTML = 'hello'
3+ // document.body.appendChild(div)
4+
5+ var h = require ( 'virtual-dom/h' )
6+ var createElement = require ( 'virtual-dom/create-element' )
7+ var diff = require ( 'virtual-dom/diff' )
8+ var patch = require ( 'virtual-dom/patch' )
9+
10+ var data = [ 'grizzly' , 'polar' , 'brown' ]
11+
12+ function render ( bears ) {
13+ bears = bears . map ( function ( bear ) {
14+ return h ( 'li' , bear )
15+ } )
16+ bears . push ( h ( 'li' , [
17+ h ( 'button' , {
18+ onclick : function ( event ) {
19+ data . push ( 'new bear' )
20+ update ( )
21+ }
22+ } , 'add bear' )
23+ ] ) )
24+ return h ( 'ul' , bears )
25+ }
26+
27+ var tree = render ( data )
28+ var rootNode = createElement ( tree )
29+ document . body . appendChild ( rootNode )
30+
31+ function update ( ) {
32+ var newTree = render ( data )
33+ var patches = diff ( tree , newTree )
34+ rootNode = patch ( rootNode , patches )
35+ tree = newTree
36+ }
Original file line number Diff line number Diff line change 1+ {
2+ "name" : " getting-started-with-virtual-dom" ,
3+ "version" : " 0.1.0" ,
4+ "description" : " " ,
5+ "main" : " index.js" ,
6+ "dependencies" : {
7+ "virtual-dom" : " ^2.0.1"
8+ },
9+ "devDependencies" : {
10+ "budo" : " ^4.0.0"
11+ },
12+ "scripts" : {
13+ "start" : " budo index.js --live"
14+ },
15+ "author" : " Kyle Robinson Young <kyle@dontkry.com> (http://dontkry.com)" ,
16+ "license" : " MIT"
17+ }
You can’t perform that action at this time.
0 commit comments