We explain here how Owl is designed
Warning: these notes are technical by nature, and intended for people working on Owl (or interested in understanding its design).
Roughly speaking, Owl has 5 main parts:
src/blockdom)src/component)src/compiler folder)src/app)src/reactivity.ts)There are some other files, but the core of Owl can be understood with these five main parts.
The virtual dom is an optimized virtual dom based on blocks, which supports multi blocks (for fragments). Everything that owl renders is internally represented by a virtual node. The job of the virtual dom is to efficiently represent the current state of the application, and to build an actual DOM representation when needed, or update the DOM whenever it is needed.
some other helpers/smaller scale stuff A rendering occurs in two phases:
There are several classes involved in a rendering:
Components are organized in a dynamic component tree, visible in the user
interface. Whenever a rendering is initiated in a component C:
C with the rendering props informationOwl is a declarative component system: we declare the structure of the component tree, and Owl will translate that to a list of imperative operations. This translation is done by a virtual dom. This is the low level layer of Owl, most developer will not need to call directly the virtual dom functions.
The main idea behind a virtual dom is to keep a in-memory representation of the DOM (called a virtual node), and whenever some change is needed, to regenerate a new representation, compute the difference between the old and the new, then apply the changes.
vdom exports two functions:
h: create a new virtual nodepatch: compare two virtual nodes, and apply the difference.Note: Owl’s virtual dom is a fork of snabbdom.