A renderer converts a virtual DOM produced from application state into the browser’s visible DOM. It keeps the view synchronized after user interactions by coordinating with the state manager. section 5.0 section 5.1
A simple renderer follows three responsibilities:
- Destroy the current DOM when an existing view must be replaced. section 5.0
- Call the top-level view function to produce a virtual DOM from the current state. section 5.0
- Mount the virtual DOM into the parent browser element, or patch the existing DOM when reconciliation is available. section 5.0 section 7.3
Rendering after a click
A user clicks a button, the browser dispatches an event, and the application’s state manager applies the configured update. After receiving notification of the changed state, the renderer produces a new view and updates the DOM. Early implementations rebuild the entire DOM; later implementations compare the previous and new virtual DOM trees with patchDOM(). section 5.1 section 7.3
Figure 5.1 Your first framework is a state manager and a renderer glued together.
Use the architecture diagram to trace how the renderer and state manager are wired together into a working framework. section 5.0
