Document Object Model (DOM)
Assignment 3 is basically this: A3-Vanilla from CS349.
This is the tree of nodes.
In general, using innerHTML
can be faster for creating large amounts of HTML content compared to individual DOM manipulations, but it does have some drawbacks. One of the main concerns with using innerHTML
is that it completely replaces the content of an element, which can lead to unintended consequences such as wiping out event listeners or data associated with existing elements.
Example:
Virtual DOM
The VDOM is a lightweight representation of the UI in memory.
Used for two purposes:
- “Render” an actual DOM using imperative methods
- Lightweight abstraction of DOM to compare changes
The VDOM is synchronized with the “real” DOM as follows:
- Save current VDOM
- Components and/or application state updates the VDOM
- A re-render is triggered by framework
- Compare VDOM before update with VDOM after update
- Reconcile the difference identifying a set of DOM patches
- Perform patch operations on real DOM
- Back to step 1
Hyperscript function calls create a representation of UI tree
- It’s a JavaScript object
- Commonly referred to as a virtual DOM (or just “vdom”)
Used for two purposes:
- “Render” an actual DOM using imperative methods
- Lightweight abstraction of DOM to compare changes