Aria 2.0.0
C++23 MVVM framework (C++20 minimum) — reactive, coroutine-first, ABI-layered
Loading...
Searching...
No Matches
aria::binding::ViewModel Class Reference

Base class for view models. More...

#include <view_model.hpp>

Inheritance diagram for aria::binding::ViewModel:
[legend]

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

SubscriptionBagbag ()
 Access the subscription bag.

Detailed Description

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.

Constructor & Destructor Documentation

◆ ViewModel()

aria::binding::ViewModel::ViewModel ( )

◆ ~ViewModel()

virtual aria::binding::ViewModel::~ViewModel ( )
virtual

Member Function Documentation

◆ is_active() [1/2]

Property< bool > & aria::binding::ViewModel::is_active ( )
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.

◆ is_active() [2/2]

const Property< bool > & aria::binding::ViewModel::is_active ( ) const
nodiscard

◆ on_activate()

virtual void aria::binding::ViewModel::on_activate ( )
inlinevirtual

◆ on_deactivate()

virtual void aria::binding::ViewModel::on_deactivate ( )
inlinevirtual

◆ activate()

void aria::binding::ViewModel::activate ( )

◆ deactivate()

void aria::binding::ViewModel::deactivate ( )

◆ add_child()

void aria::binding::ViewModel::add_child ( std::shared_ptr< ViewModel > child)

◆ track()

void aria::binding::ViewModel::track ( Subscription sub)

Add a subscription that will be released on destruction.

◆ add_destroy_hook()

void aria::binding::ViewModel::add_destroy_hook ( std::function< void()> hook)

◆ bag()

SubscriptionBag & aria::binding::ViewModel::bag ( )
nodiscardprotected

Access the subscription bag.

Subclass VMs use this to attach subscriptions that auto-clean on deactivation/destruction.


The documentation for this class was generated from the following file: