A shopping cart may have one web component showing its items and another showing the item count and total price. When the cart changes, both displays need to stay synchronized. Mutable shared state gives multiple components access to the same changing data. section 3.11
Vanilla web components have no built-in state-sharing mechanism. One approach keeps state in an ancestor, passes it down through component properties, and listens for bubbling events from descendants that request changes. It works, but passing data through components that do not use it can be tedious and error prone. section 3.11 section 3.12
One name, three components
A FAST state object starts with a name of "World". A labeled input reads that name and replaces the state when its change event fires; a greeting reads the same name and updates automatically. A parent component can also reset the state to "World". The input, greeting, and reset action therefore coordinate without passing the name through the component hierarchy. section 7.11
import { state } from "@microsoft/fast-element/state.js";
export const myState = state({ name: "World" });
The short state definition creates the shared object used by the components. section 7.11
With FAST, components read `myState.current.name` and make changes through `myState.set(...)`. The input example creates a replacement object that preserves other current properties while changing `name`. Related shared properties can be grouped in one state object, or separated into multiple objects. Choose an explicit ancestor-and-events flow for vanilla components, or a library’s state support when that plumbing becomes cumbersome. section 7.11 section 3.11







