Skip to content

Instantly share code, notes, and snippets.

@kyuwoo-choi
Last active May 28, 2018 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kyuwoo-choi/ddb517065f3c8d3af3840d1dd795b494 to your computer and use it in GitHub Desktop.
Save kyuwoo-choi/ddb517065f3c8d3af3840d1dd795b494 to your computer and use it in GitHub Desktop.
// Virtual DOM example
var tree = render(count); // We need an initial tree
var rootNode = createElement(tree); // Create an initial root DOM node ...
document.body.appendChild(rootNode); // ... and it should be in the document
setInterval(function () {
count++;
var newTree = render(count);
var patches = diff(tree, newTree);
rootNode = patch(rootNode, patches);
tree = newTree;
}, 1000);
// jsx example
const element = (
<div>
<h1>Hello!</h1>
<h2>Good to see you here.</h2>
</div>
);
render(element);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment