|
Aria 2.0.0
C++23 MVVM framework (C++20 minimum) — reactive, coroutine-first, ABI-layered
|
Base class for view models. More...
#include <view_model.hpp>
Public Member Functions | |
| ViewModel () | |
| virtual | ~ViewModel () |
| Property< bool > & | is_active () |
| Activation state (Property<bool>). | |
| const Property< bool > & | is_active () const |
| virtual void | on_activate () |
| virtual void | on_deactivate () |
| void | activate () |
| void | deactivate () |
| void | add_child (std::shared_ptr< ViewModel > child) |
| void | track (Subscription sub) |
| Add a subscription that will be released on destruction. | |
| void | add_destroy_hook (std::function< void()> hook) |
Protected Member Functions | |
| SubscriptionBag & | bag () |
| Access the subscription bag. | |
Base class for view models.
Provides lifecycle, child management, and a subscription bag that auto-cleans up on destruction.
For structured concurrency (auto-cancel of in-flight coroutines on VM destruction), use the ViewModelScope helper from aria/binding/view_model_scope.hpp.
The dtor / activate / deactivate / add_child / add_destroy_hook impls live out-of-line in view_model.cpp so the vtable is emitted exactly once inside the binding library (matters on Windows DLL builds, reduces code size, and speeds compilation of every TU that only uses the interface).
MSVC C4251: enable_shared_from_this<ViewModel> contains a weak_ptr whose layout is guaranteed by the C++ Standard Library ABI. All other STL members have been moved into the Impl. Suppression is safe.
| aria::binding::ViewModel::ViewModel | ( | ) |
|
virtual |
|
nodiscard |
Activation state (Property<bool>).
Returns a reference so consumers can call .get(), .set(v), .on_changed(...) etc. as before. The backing store lives in Impl, keeping the DLL interface clean.
|
nodiscard |
|
inlinevirtual |
|
inlinevirtual |
| void aria::binding::ViewModel::activate | ( | ) |
| void aria::binding::ViewModel::deactivate | ( | ) |
| void aria::binding::ViewModel::add_child | ( | std::shared_ptr< ViewModel > | child | ) |
| void aria::binding::ViewModel::track | ( | Subscription | sub | ) |
Add a subscription that will be released on destruction.
| void aria::binding::ViewModel::add_destroy_hook | ( | std::function< void()> | hook | ) |
|
nodiscardprotected |
Access the subscription bag.
Subclass VMs use this to attach subscriptions that auto-clean on deactivation/destruction.