liveBook · Manning

Chapter 13: Data binding and reactivity

What you will learn in chapter 13 of Vanilla Web

The introduction frames data binding as keeping a Vanilla app’s interface synchronized with changing data in both directions, without a framework runtime.

After this chapter you will be able to

What it builds on

Section by section

Introduction

The introduction frames data binding as keeping a Vanilla app’s interface synchronized with changing data in both directions, without a framework runtime.

Key terms: dynamic data binding, Vanilla app, framework runtime

13.1 Reactive thinking

Defines reactive thinking as predictable updates to data-dependent UI, identifies state, derived data, and effects, and contrasts framework models with choosing a small Vanilla JavaScript pattern.

Key terms: reactive programming, state, derived data, effects, frameworks, Vanilla JavaScript, small pattern

13.2 Data binding techniques

Introduces data binding as a two-way flow between state and the UI and explains why browser primitives can support it without a framework.

Key terms: data binding, state, UI, reactivity, events, DOM, queueMicrotask(), Proxy, EventTarget

13.2.1 Direct DOM binding

This section shows how direct DOM binding connects state to displayed content and user events, and cautions against relying on element IDs as global variables.

Key terms: state object, render function, state.count, data binding, id, window, document.getElementById, scoped queries

13.2.2 Derived bindings

This section explains how to compute a UI value from source state during rendering, alongside a direct DOM binding pattern and a naming collision in the example.

Key terms: derived data, state, rendering, subtotal, Direct DOM binding, render function, event listeners, calcSubtotal, window.subtotal, <output id="subtotal">

13.2.3 A render function with queueMicrotask()

This section shows how a state object, form input, and a render function can make a small interface reactive, then uses queueMicrotask() to batch renders after synchronous state changes.

Key terms: state object, render function, input event, two-way binding, formData.getAll(name), Object.fromEntries(), plain object, repeated checkboxes, queueMicrotask(), scheduleRender()

13.2.4 Binding through data-* attributes

This section shows how small pages can use data-* attributes as visible binding markers, while explaining the helper’s manual updates, limits, and XSS risk.

Key terms: data-bind, data-bind-attr, readPath(), dotted path, state object, renderBindings(), rendering pass, reactive system, disabled attribute, <template>-based component

13.2.5 Binding with template strings

This section explains how template strings can render HTML, why interpolated values must be escaped, and when replacing markup is an acceptable tradeoff.

Key terms: template strings, innerHTML, HTML-escaped, interpolated value, event delegation, DOM nodes

13.2.6 Binding with <template>

This section presents <template> as a binding approach that clones predefined HTML and fills it using DOM APIs.

Key terms: <template>, template strings, DOM APIs

13.2.7 EventTarget stores

This section explains how an EventTarget-based store can share state across page components and how subscribers and web components manage subscriptions.

Key terms: explicit store, EventTarget, shared state, subscribe(), listener, current state, change event, connectedCallback(), disconnectedCallback(), #unsubscribe

13.2.8 Proxy

This section explains how Proxy can make object property changes reactive, including nested state, and where the approach needs care.

Key terms: Proxy, target, handler, traps, get trap, set trap, Reflect.get(), Reflect.set(), shallow, WeakMap

13.2.9 Signals through a micro-library

This section explains how signals support reactive bindings, why a small library is the practical choice for production code, and how another emerging browser API relates to reactivity.

Key terms: signal, effect, dependency tracking, subtotal.value, Signal class, @preact/signals-core, signal(), computed(), effect(), batch()

13.2.10 Choosing a binding pattern

This section gives criteria for choosing a data-binding pattern and shows how CSS can handle presentation when JavaScript reflects state into the DOM.

Key terms: render functions, EventTarget-based stores, Proxy-based state, signals, explicit control, ergonomics, data-status, CustomStateSet, CSS selectors, :state()

13.3 State management

Explains why state management in most Vanilla apps is more about discipline than a heavy library.

Key terms: state management library, state bugs, duplicated values, hidden side effects, asynchronous work, UI state

13.3.1 Design patterns

This section gives practical rules for keeping plain JavaScript UI state consistent, responsive, and easy to inspect.

Key terms: source of truth, Derive instead of duplicating, visibleItems, async state, loading, ready, empty, error, state transition, Co-locate state

13.4 Data validation

This section explains where to validate incoming data, why browser validation is the starting point for forms, and why network and stored data should be parsed before use.

Key terms: built-in validation, required, type, minlength, pattern, checkValidity(), boundaries, normalize early, fail fast, parsing

13.5 Summary

Where this is used later

Concepts explained in this chapter

← Chapter 12: Working with data Chapter 14: Beyond basics →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.