|
Ultralight C++ API 2.0.0
|
#include <Ultralight/dom/data/Model.h>
Handle passed to a type's static Sync function to control which fields are read during synchronization.
When Context::Sync() runs, the library normally reads every field of every bound instance through its schema. You can customize this process for any described type by declaring a static Sync function that takes your instance alongside a Model.
It provides access to previously synchronized values and lets you choose which fields to read. This avoids reading large containers or calling expensive accessors on frames where the underlying data hasn't changed.
This leaderboard reads its row collection only when its revision counter changes:
You declare a static Sync function beside the type's schema, either inside the type itself or within its dom::data::TypeTraits specialization.
The library never resends unchanged values to attached pages, with or without a static Sync function. Skipping a field saves only the work of reading it in native code.
When you skip syncing a field, the page keeps its last synchronized value. For collections gated on a revision counter, tag the counter with dom::data::Internal in the schema. Markup can't bind an Internal entry, and schema tools leave it out.
Each function plays a distinct role during synchronization:
Public Member Functions | |
| template<ultralight::detail::FixedString Name> | |
| void | Sync () |
| Sync one field by name. | |
| void | SyncAll () |
| Sync every field (what Context::Sync() does for a type without a Sync function). | |
| template<ultralight::detail::FixedString... Names> | |
| void | SyncAllExcept () |
| Sync every field except the ones you list (eg, m.SyncAllExcept<"rows", "log">()). | |
| template<ultralight::detail::FixedString Name, typename Arg> | |
| void | Set (const Arg &value) |
| Set a field's value by name. | |
| Public Member Functions inherited from Snapshot< T > | |
| template<ultralight::detail::FixedString Name> | |
| auto | Get () const |
| Get the value of a field or Var by name. | |
Additional Inherited Members | |
| Public Types inherited from Snapshot< T > | |
| using | described_type = T |
| Static Public Member Functions inherited from Snapshot< T > | |
| static constexpr const auto & | schema () |
| Get the type's schema. | |
| Protected Member Functions inherited from Snapshot< T > | |
| template<ValueKind K> | |
| auto | ReadSlot (uint32_t slot) const |
| Static Protected Member Functions inherited from Snapshot< T > | |
| template<ultralight::detail::FixedString Name> | |
| static consteval size_t | IndexOfChecked () |
| Protected Attributes inherited from Snapshot< T > | |
| detail::RecordOps * | ops_ |
|
inline |
Set a field's value by name.
This is how you send a field declared without an accessor (eg, dd::Field<int>("score")). It also works on any other field or Var with a single value.
| value | The value to send. It must convert to the field's declared type. |
|
inline |
Sync one field by name.
Reads the field from your instance and sends it to the page if it changed. A nested object or a list syncs each object or row through its own type's Sync function.
|
inline |
Sync every field (what Context::Sync() does for a type without a Sync function).
Actions and fields without an accessor are skipped.
|
inline |
Sync every field except the ones you list (eg, m.SyncAllExcept<"rows", "log">()).
Actions and fields without an accessor are skipped. A name that isn't in the schema is a compile error.