ui::Subscription¶
Header: winui/core/Property.hpp.
One edge of the observer graph: keeps a handler registered on a Property or Signal for as long as it lives, owned by the observer.
Move-only. Destroying, reset()ting or move-assigning over it unsubscribes; if the observed Property dies first the subscription goes dead (alive() turns false), so either end may be destroyed first. Not a template, so an Element holds bindings of any value type in one std::vector
Example:
ui::Property<int> count{0};
auto label = std::make_unique<ui::TextControl>("0");
ui::TextControl* observer = label.get();
// Owned by the label: unsubscribes when the label is destroyed.
label->add_subscription(count.observe([observer](const int& n) {
observer->set_text(std::to_string(n));
}));
// Or held by hand for a scoped observation.
ui::Subscription sub = count.observe([](const int& n) { std::printf("%d\n", n); });
count = 1; // both handlers fire
sub.reset(); // only the label's remains
Subscription¶
A dead subscription observing nothing; alive() is false.
~Subscription¶
Unsubscribes (see reset()).
Subscription¶
Not copyable: one subscription is one edge.
operator=¶
Not copyable: one subscription is one edge.
Subscription¶
Takes over other's place in the observer list; other is left dead.
operator=¶
Unsubscribes this one, then takes over other's place; other is left dead.
reset¶
Unsubscribe now. Idempotent, and safe after the observed Property has been destroyed.
alive¶
False once this subscription has been reset(), moved from, or had its Property destroyed out from under it.