5#include "aria/detail/typed_signal.hpp"
57template<
typename... Args>
60 using Action = std::function<void(Args...)>;
61 using Predicate = std::function<bool(
const Args&...)>;
64 template<std::invocable<Args...> A>
66 : action_(
std::forward<A>(action)),
67 predicate_([](const Args&...) noexcept { return true; }),
68 can_signal_(std::make_shared<CanExecuteSignal>()) {}
70 template<std::invocable<Args...> A, std::predicate<
const Args&...> P>
72 : action_(
std::forward<A>(action)),
73 predicate_(
std::forward<P>(predicate)),
92 if (predicate_(args...)) {
107 return predicate_(args...);
123 can_signal_->emit(predicate_(args...));
127 return can_signal_->connect(std::move(fn));
132 std::weak_ptr<void> lifetime_token_() {
133 if (!lifetime_) lifetime_ = std::make_shared<char>();
137 Predicate predicate_;
138 std::shared_ptr<CanExecuteSignal> can_signal_;
139 std::shared_ptr<void> lifetime_;
160 template<std::invocable<> A>
162 : action_(
std::forward<A>(action)),
163 predicate_([]() noexcept { return true; }),
164 can_signal_(std::make_shared<CanExecuteSignal>()) {
168 template<std::invocable<> A, std::predicate<> P>
170 : action_(
std::forward<A>(action)),
171 predicate_(
std::forward<P>(predicate)),
200 auto signal = can_signal_;
201 auto last = std::make_shared<bool>();
203 [pred = predicate_, signal, last,
204 primed = std::make_shared<bool>(
false)]()
mutable {
205 const bool now = pred();
258 can_signal_->emit(predicate_());
262 return can_signal_->connect(std::move(fn));
267 std::weak_ptr<void> lifetime_token_() {
268 if (!lifetime_) lifetime_ = std::make_shared<char>();
272 Predicate predicate_;
273 std::shared_ptr<CanExecuteSignal> can_signal_;
279 std::optional<reactive::Effect> effect_;
280 std::shared_ptr<void> lifetime_;
Definition command.hpp:154
Command & operator=(Command &&)=delete
Command(const Command &)=delete
Command(A &&action, P &&predicate)
Definition command.hpp:169
Command(A &&action)
Definition command.hpp:161
bool can_execute() const
Definition command.hpp:247
detail::TypedSignal< bool > CanExecuteSignal
Definition command.hpp:158
Subscription observe_can_execute(std::function< void(bool)> fn)
Definition command.hpp:261
void operator()()
Definition command.hpp:245
void notify_can_execute_changed() const
Force-emit a can_execute notification.
Definition command.hpp:253
std::function< void()> Action
Definition command.hpp:156
std::function< bool()> Predicate
Definition command.hpp:157
void execute()
Definition command.hpp:232
Command & operator=(const Command &)=delete
Command(Command &&)=delete
~Command()
Definition command.hpp:230
bool can_execute(const Args &... args) const
Definition command.hpp:106
Command(A &&action)
Definition command.hpp:65
void notify_can_execute_changed(const Args &... args) const
Manually notify observers that can_execute may have changed.
Definition command.hpp:118
Command(Command &&)=delete
Command(A &&action, P &&predicate)
Definition command.hpp:71
std::function< bool(const Args &...)> Predicate
Definition command.hpp:61
void operator()(const Args &... args)
Definition command.hpp:104
detail::TypedSignal< bool > CanExecuteSignal
Definition command.hpp:62
Subscription observe_can_execute(std::function< void(bool)> fn)
Definition command.hpp:126
std::function< void(Args...)> Action
Definition command.hpp:60
Command & operator=(const Command &)=delete
Command(const Command &)=delete
Command & operator=(Command &&)=delete
void execute(const Args &... args)
Invoke the action if can_execute(args...) is true.
Definition command.hpp:91
~Command()
Definition command.hpp:88
RAII handle to a single subscription.
Definition subscription.hpp:44
BindingEngine: connects ViewModel properties to platform views via an adapter.
Definition binding_engine.hpp:103
Definition binding_engine.hpp:25
void publish_trace_unchecked(const TraceEvent &event) noexcept
Publish an already-built event using one owning sink snapshot.
Definition diagnostics.hpp:293
bool has_trace_sink() noexcept
True iff a sink is currently installed.
Definition diagnostics.hpp:286
@ Command
Synchronous Command<Args...> execution.
Definition diagnostics.hpp:70
Definition validation_key.hpp:110
Synchronous Command<Args...> events.
Definition diagnostics.hpp:153