A value has a location
A Data Bag holds values and node attributes. A literal path identifies a location. A leading dot resolves against the current datapath, so a customer branch can refer to .name without repeating the whole prefix.
The current declaration is dataSetter. Nested dictionaries become Bags recursively. It is initialization, not a persistence service, and a literal JSON string stays a string. The old data declaration is not an alias.
root.dataSetter("customer", {"name": "Ada", "city": "London"})
panel = root.div(datapath="customer")
panel.h2("^.name")
panel.p("^.city")Read the first render carefully
Data setters for an inserted branch are installed before its DOM is built. A setter written after a visual declaration can therefore still supply the first displayed value. Multiple setters for the same path follow document order.
Keep calculated totals outside a collection you intend to sum. Otherwise the result can become one of its own inputs. Initial values, derived values and saved records have different jobs.
Your turn
Try it yourself
- Open Setters and defaults. Find a setter that appears after a control in Source.
- Reload and confirm that the control already shows the initialized value.
- Compare the Data path with the control’s default: identify which supplies the initial state.
Check your understanding
If a setter receives a JSON string, will it parse the string into a Bag?
Show the answer and expected result
No. A dictionary/object is converted recursively; a JSON string remains text. Parsing external input is a separate operation. Removing a setter declaration also does not delete the value it previously installed.