template<typename T>
class ultralight::dom::data::Snapshot< T >
Read-only access to the synchronized values of a described type.
Snapshot lets you inspect the field values and CSS variables recorded for a described type without touching the underlying C++ instance. Calling Get() with an entry name returns its current synchronized value.
This schema uses a validator to check an edited bid against another field on the page:
struct Shop {
int64_t gold = 500;
int64_t bid = 0;
static constexpr auto schema = dd::Schema(
dd::Field("gold", &Shop::gold),
dd::Field("bid", &Shop::bid, dd::Editable,
dd::Validate([](int64_t bid, auto s) -> std::optional<int64_t> {
return std::nullopt;
return bid;
})));
};
static constexpr const auto & schema()
Get the type's schema.
Definition Model.h:83
auto Get() const
Get the value of a field or Var by name.
Definition Model.h:104
Receiving a Snapshot
The library passes a Snapshot to functions that inspect page state:
- A validator receives a Snapshot through its second parameter on the Renderer's thread. It provides the values the page currently shows, letting you inspect related fields before accepting an edit.
- A type's static Sync function receives a dom::data::Model, which inherits from Snapshot. Calling Get() returns the last synced values, including any fields that call has already synced, so you can compare against native data and skip unchanged fields (see dom::data::Model).
- See also
- dom::data::Model, dom::data::Validate()