How uihp-challenges/uihp-challenges-april23 works
1. This repo is a browser-only learning scaffold, not a production app. The architecture is a single static page in challenges/index.html plus one stylesheet and five alternative JavaScript entrypoints (part1.js through part5.js). There is no build step, no bundler, no backend, and no external data source.
2. The main architectural boundary is the browser itself: HTML creates the DOM, CSS creates the CSSOM, and JavaScript runs in the browser runtime with direct access to document, events, timers, and element properties. The code is about progressively moving from manual DOM edits to state-driven rendering.
3. index.html is the only entrypoint. It initially contains the view container and switches which lesson script runs by changing the <script src> from one part file to another. That means only one JS model is active at a time; the parts are not composed together.
4. styles.css is a separate presentation layer applied to the static DOM. It does not drive behavior; it only affects how the browser renders the elements that the JavaScript creates or updates.
5. Part 1 is the simplest UI loop: JavaScript queries existing DOM nodes, stores them in local variables, updates textContent, and wires an input event handler. The data flow is user input -> event handler -> JS variable -> DOM mutation. This is direct, imperative DOM manipulation.
6. Part 2 introduces one-way data binding. The important boundary becomes “data” versus “view”: event handlers update JS state, then a single dataToView function copies that state into DOM properties. A timer (setInterval) can force repeated view refreshes, so the view is treated as a projection of current state.
7. Part 3 shifts from selecting existing elements to creating them from a “virtual DOM” description. The UI is described as arrays of element metadata, then convert turns each description into a real DOM node. The view is now generated from data rather than manually edited, and the DOM is replaced as a whole on each update.
8. Part 4 generalizes composition. Instead of converting two hardcoded nodes, the code maps over an arbitrarily sized vDOM list to produce a list of element objects, then appends/replaces them in the document body. This is the repo’s flexible composition layer: list in, list out, render all.
9. Part 5 adds a shared state store and update hook. Data moves into a single data object, and updateData(label, value) becomes the only sanctioned write path. After any state change, updateDOM runs, so state changes and rendering are coupled through one boundary rather than scattered across event handlers.
10. Also in Part 5, rendering becomes incremental with a diffing/reconciliation step. prevVDOM preserves the previous virtual tree, findDiff compares it to the current tree, and only changed nodes are reconciled back into the actual DOM. The architecture here is “state store -> vDOM generation -> diff -> minimal DOM updates.”
11. The repo’s reusable conceptual pipeline is: browser event -> handler -> state update -> virtual description -> DOM conversion -> render. Each later part tightens that pipeline by reducing where state can change and how much of the DOM must be recreated.
12. There are no server, API, routing, persistence, or component-library boundaries here. The only meaningful external interfaces are standard browser APIs: DOM querying/creation, event handling, timers, and focus/selection behavior. That makes the project a pure client-side UI architecture exercise.
Main entry points: index.html Index page · part5.js Part 5 · part1.js Part 1 · part2.js Part 2
Components 17
Browser platform
Standard browser runtime and rendering boundaries.
- Browser · The execution environment that provides DOM, events, timers, and rendering.
- DOM · Live document tree mutated or regenerated by the lesson scripts.
- CSSOM · Style model used by the browser to render the page.
- JS runtime · Browser JavaScript environment with access to document, properties, and timers.
- Events · User input and DOM events that trigger updates.
- Timers · Timer-driven refresh used in the state-to-view lesson.
Static shell
Single HTML entrypoint and stylesheet for the lesson page.
- Index page · Single browser entrypoint that loads one lesson script at a time.
challenges/index.html - Stylesheet · Static CSS that affects rendering but not behavior.
challenges/styles.css
Lesson parts
Alternative JavaScript entrypoints showing progressively richer UI architecture.
- Part 1 · Queries existing nodes, stores references, and mutates text content directly.
challenges/part1.js - Part 2 · Separates data from view and copies state into the DOM through one-way binding.
challenges/part2.js - Part 3 · Builds UI from element descriptions and converts them into real DOM nodes.
challenges/part3.js - Part 4 · Maps a variable-length virtual DOM list into rendered elements and replaces the body content.
challenges/part4.js - Part 5 · Uses a shared data store, centralized updates, and diff-based reconciliation.
challenges/part5.js - State store · Single source of truth for lesson data in the final part.
- Virtual DOM · Structured view description used to generate or reconcile real DOM.
- Diff engine · Compares previous and current virtual trees to find minimal changes.
- Render step · Converts view descriptions into DOM updates or replacements.
Connections 30
- Browser → Index page: loads · The browser loads the single HTML entrypoint.
- Browser → CSSOM: applies · The browser parses the stylesheet into the style model.
- Index page → Part 1: switches to · The HTML page can point its script tag at the first lesson entrypoint.
- Index page → Part 2: switches to · The HTML page can point its script tag at the second lesson entrypoint.
- Index page → Part 3: switches to · The HTML page can point its script tag at the third lesson entrypoint.
- Index page → Part 4: switches to · The HTML page can point its script tag at the fourth lesson entrypoint.
- Index page → Part 5: switches to · The HTML page can point its script tag at the fifth lesson entrypoint.
- Stylesheet → CSSOM: drives · Stylesheet rules shape how the browser renders the page.
- Part 1 → DOM: mutates · Directly updates existing DOM nodes.
- Part 1 → Events: listens · Uses input events to react to user changes.
- Events → Part 1: triggers · User input calls the handler that mutates the DOM.
- Part 2 → State store: updates · Event handlers update state rather than directly editing the view.
- Part 2 → Render step: projects · State is copied into DOM properties through a view function.
- Timers → Part 2: refreshes · Periodic updates can force repeated view synchronization.
- Part 3 → Virtual DOM: describes · The UI is represented as structured metadata.
- Virtual DOM → Render step: converts · Virtual descriptions are turned into real DOM nodes.
- Render step → DOM: replaces · The rendered DOM is regenerated as a whole.
- Part 4 → Virtual DOM: maps · Processes an arbitrarily sized list of view descriptions.
- Part 4 → Render step: appends · Renders the mapped list into the document body.
- Part 5 → State store: stores · Uses one shared object as the state source.
- Part 5 → Diff engine: compares · Compares previous and current virtual trees.
- Diff engine → Render step: limits · Only changed nodes are reconciled to the DOM.
- Part 5 → Render step: triggers · State updates automatically invoke DOM refresh.
- JS runtime → Part 1: executes · Browser JavaScript runs the lesson scripts.
- JS runtime → Part 2: executes · Browser JavaScript runs the lesson scripts.
- JS runtime → Part 3: executes · Browser JavaScript runs the lesson scripts.
- JS runtime → Part 4: executes · Browser JavaScript runs the lesson scripts.
- JS runtime → Part 5: executes · Browser JavaScript runs the lesson scripts.
- Browser → Events: dispatches · The browser delivers user interaction events.
- Browser → Timers: schedules · The browser provides timer callbacks.