liveBook · Manning

Source of truth

As explained in Web Component Development with Modern Libraries and Tooling

The authoritative location of a data value from which other representations of that value are derived or synchronized.

A source of truth is the authoritative home of a data value. Other representations delegate to it, giving users multiple ways to read or change the same state without allowing those representations to diverge. section 3.3

Web components commonly use this pattern for two practical reasons:

  • Attributes let HTML specify component data, while properties let JavaScript access the same data more directly. section 3.3
  • Frameworks such as React and Vue may synchronize same-named attributes and properties, so components should keep those interfaces consistent. section 3.3

HelloWorld with an attribute as the source

The `name` attribute owns the value. The `name` property getter reads it, the setter writes it, and observed attribute changes trigger rendering. Editing `<hello-world name="Alpha">` in DevTools therefore changes the display to “Hello, Alpha!”; changing it to “Beta” updates the result again. section 3.3

The same synchronization rule also supports server-rendered custom elements. A property-backed component can update an existing attribute and rendered shadow content, while Declarative Shadow DOM supplies initial markup before client-side behavior is connected. section 11.2

How Web Component Development with Modern Libraries and Tooling covers it

How deep it goes
Explains authoritative state, getter-setter delegation, observed-attribute rendering, and SSR synchronization, but not broader state-management architecture.
Examples
Uses a HelloWorld component whose name changes from Alpha to Beta through DevTools, plus property-backed and server-rendered variants.
What it assumes
Assumes basic HTML, JavaScript, and web-component concepts while demonstrating the synchronization mechanics directly.
What you can do after
Build interoperable web components that synchronize attributes, properties, rendering, and server-rendered initial content.
How it connects
Connects web components with custom elements, HTML attributes, JavaScript properties, server-side rendering, and Declarative Shadow DOM.

Also explained in

Compare how 13 books explain source of truth →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Web Component Development with Modern Libraries and Tooling. The section links point to the parts of the book it draws on.