Aria 2.0.0
C++23 MVVM framework (C++20 minimum) — reactive, coroutine-first, ABI-layered
Loading...
Searching...
No Matches
view_model.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "aria/abi/export.hpp"
4#include "aria/property.hpp"
6
7#include <functional>
8#include <memory>
9#include <vector>
10
11namespace aria::binding {
12
28#ifdef _MSC_VER
29#pragma warning(push)
30#pragma warning(disable: 4251)
31#endif
32class ARIA_BINDING_API ViewModel : public std::enable_shared_from_this<ViewModel> {
33public:
35 virtual ~ViewModel();
36
40 [[nodiscard]] Property<bool>& is_active();
41 [[nodiscard]] const Property<bool>& is_active() const;
42
43 virtual void on_activate() {}
44 virtual void on_deactivate() {}
45
46 void activate();
47 void deactivate();
48
49 void add_child(std::shared_ptr<ViewModel> child);
50
53
54 void add_destroy_hook(std::function<void()> hook);
55
56protected:
59 [[nodiscard]] SubscriptionBag& bag();
60
61private:
62 struct Impl;
63 std::unique_ptr<Impl> impl_;
64};
65#ifdef _MSC_VER
66#pragma warning(pop)
67#endif
68
81
82} // namespace aria::binding
Aggregate holder: owns multiple Subscriptions and drops them together.
Definition subscription.hpp:116
RAII handle to a single subscription.
Definition subscription.hpp:44
Base class for view models.
Definition view_model.hpp:32
const Property< bool > & is_active() const
SubscriptionBag & bag()
Access the subscription bag.
void track(Subscription sub)
Add a subscription that will be released on destruction.
void add_child(std::shared_ptr< ViewModel > child)
virtual void on_activate()
Definition view_model.hpp:43
void add_destroy_hook(std::function< void()> hook)
virtual void on_deactivate()
Definition view_model.hpp:44
Property< bool > & is_active()
Activation state (Property<bool>).
Definition property.hpp:103
#define ARIA_BINDING_API
Definition export.hpp:39
Definition binding_engine.hpp:25
ViewModel IViewModel
IViewModel is an alias for ViewModel, provided for users coming from WPF / Avalonia / MAUI where the ...
Definition view_model.hpp:80