liveBook · Manning

Reactive programming

As explained in Vanilla Web

Reactivity is a programming model in which changes to data automatically propagate to dependent computations or interface output.

Reactive programming keeps interface parts that depend on data predictably updated when that data changes. Its basic flow is user input, state updates, derived-data computation, and effects such as rendering the DOM. section 13.1

user event → update state → compute derived data → update the DOM

Follow the data through the reactive flow, from a user event to state, derived data, and the DOM. section 13.1

Reactivity is not exclusive to frameworks, but the browser does not automatically track arbitrary data changes. Vanilla JavaScript uses browser primitives to build explicit bindings and updates; choose the smallest pattern that fits the page. section 13.2 section 7.4

Vanilla approaches trade explicitness for convenience:

  • Start with direct DOM bindings or data-* bindings; these are enough for many real apps. section 13.2
  • For other needs, consider template strings, <template> cloning, EventTarget stores, Proxy wrappers, or signals. section 13.2
  • Keep both directions visible: render state into the DOM, and use input or change events to write user actions back into state. section 13.2

Custom Elements do not provide built-in reactivity, so property changes may require extra code to update the DOM. Project-specific reactive UI can also be cumbersome with components alone. section 7.4

How Vanilla Web covers it

How deep it goes
Defines state, derived data, and effects, then surveys binding patterns without prescribing one implementation.
Examples
Uses count and query/product state, computed todo counts and totals, and user input flowing between state and the DOM.
What it assumes
Assumes familiarity with data entering and being stored in a Vanilla app, then defines reactive flow in practical terms.
What you can do after
Apply it via browser events and DOM updates to keep data and interface synchronized with a chosen small pattern.
How it connects
Connects state, derived data, effects, data binding, DOM updates, browser events, Proxy, EventTarget, and signals.

Also explained in

Compare how 8 books explain reactive programming →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Vanilla Web. The section links point to the parts of the book it draws on.