Skip to content
Virtual DOM Trees
step 1/5

Reading — step 1 of 5

Read

~1 min readReactive Foundations

Virtual DOM Trees

A virtual node (vnode) is a plain JS object representing UI:

javascript

JSX (<div className="card"><h1>Hello</h1></div>) compiles to this:

javascript

For our build:

python

Components are functions returning vnodes:

python

When type is a function: call it during rendering.

Initial render: convert vnode → real DOM.

python

For our toy: simulate DOM with a Python tree representation. Test stdin/stdout.

Re-render: build new vtree, diff against old, apply changes.

Why virtual DOM?

  • Plain JS objects are cheap to create.
  • Plain JS comparisons are cheap.
  • Real DOM updates are expensive.
  • Build cheap tree, diff, apply minimal changes to real DOM.

Discussion

Ask a question, share an insight, or help someone who’s stuck.

Sign in to post a comment or reply.

Loading…