18 template <
typename RetT,
typename...
ArgsT>
23 template <
typename ValueT>
28 return onEvent(obs.
value());
36 template <
typename ValueT>
37 requires std::is_scalar_v<ValueT>
42 return onEvent(obs.
value());
50 template <
typename ValueT>
53 return listen(eventContext, obs, [onEvent = std::move(onEvent)](ValueT
const& value) {
59 template <
typename ValueT>
60 requires std::is_scalar_v<ValueT>
63 return listen(eventContext, obs, [onEvent = std::move(onEvent)](ValueT value) {
69 template <
typename ValueT,
typename FunctionT>
71 (std::invocable<FunctionT, ValueT const&> || std::invocable<FunctionT, ValueT>) &&
72 !Detail::IsStdFunction<FunctionT>::value)
75 return listen(eventContext, obs, std::function(std::forward<FunctionT>(onEvent)));
78 template <
typename ValueT>
82 std::function<
bool(ValueT
const&)> onEvent)
85 [weak = std::weak_ptr<Observed<ValueT>>{obs}, onEvent = std::move(onEvent)](
auto) {
86 if (
auto obs = weak.lock(); obs)
87 return onEvent(obs->
value());
90 [weak = std::weak_ptr<Observed<ValueT>>{obs}]() {
91 return !weak.expired();
96 template <
typename ValueT>
97 requires std::is_scalar_v<ValueT>
101 std::function<
bool(ValueT)> onEvent)
104 [weak = std::weak_ptr<Observed<ValueT>>{obs}, onEvent = std::move(onEvent)](
auto) {
105 if (
auto obs = weak.lock(); obs)
106 return onEvent(obs->
value());
109 [weak = std::weak_ptr<Observed<ValueT>>{obs}]() {
110 return !weak.expired();
115 template <
typename ValueT>
119 std::function<
void(ValueT
const&)> onEvent)
121 return listen(eventContext, obs, [onEvent = std::move(onEvent)](ValueT
const& value) {
127 template <
typename ValueT>
128 requires std::is_scalar_v<ValueT>
132 std::function<
void(ValueT)> onEvent)
134 return listen(eventContext, obs, [onEvent = std::move(onEvent)](ValueT value) {
140 template <
typename ValueT,
typename FunctionT>
142 (std::invocable<FunctionT, ValueT const&> || std::invocable<FunctionT, ValueT>) &&
143 !Detail::IsStdFunction<FunctionT>::value)
146 return listen(eventContext, obs, std::function(std::forward<FunctionT>(onEvent)));
149 template <
typename ValueT,
typename FunctionT>
151 (std::invocable<FunctionT, ValueT const&> || std::invocable<FunctionT, ValueT>) &&
152 !Detail::IsStdFunction<FunctionT>::value)
158 template <
typename ValueT,
typename FunctionT>
160 (std::invocable<FunctionT, ValueT const&> || std::invocable<FunctionT, ValueT>) &&
161 !Detail::IsStdFunction<FunctionT>::value)
This object can be copied with low cost.
Definition event_context.hpp:38
EventIdType registerEvent(Event event)
Definition event_context.hpp:52
ContainedT & value()
Definition observed_value.hpp:372
void attachEvent(EventContext::EventIdType eventId) const
Definition observed_value.hpp:100
Definition observed_value.hpp:1283
static constexpr auto extractJsonMember(nlohmann::json const &json) -> decltype(auto)
Definition rpc_hub.hpp:29
Definition file_dialog.hpp:6
void listen(EventContext &eventContext, Observed< ValueT > const &obs, std::function< bool(ValueT const &)> onEvent)
Definition listen.hpp:24
thread_local EventContext globalEventContext
Definition event_context.cpp:5
Definition observed_value.hpp:1546