Created
March 11, 2016 16:14
-
-
Save zkochan/891a16fc4f9846f7363d to your computer and use it in GitHub Desktop.
create-app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
module.exports = createApp; | |
var createElement = require('virtual-dom/create-element'); | |
var diff = require('virtual-dom/diff'); | |
var patch = require('virtual-dom/patch'); | |
function createApp(mount) { | |
var tree; | |
var node; | |
return function(newTree) { | |
if (!tree) { | |
tree = newTree; | |
node = createElement(tree); | |
mount.appendChild(node); | |
return; | |
} | |
var patches = diff(tree, newTree); | |
node = patch(node, patches); | |
tree = newTree; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment