morph 0.1.0
Asynchronous bridge between GUI thread and business models
Loading...
Searching...
No Matches
morph::reactive::Subscription< R > Class Template Referencefinal

The latest R the bridge published on a handler's instance, as reactive state. More...

#include <control.hpp>

Public Member Functions

template<typename M, typename S>
 Subscription (Runtime &runtime, bridge::BridgeHandler< M, S > &handler)
 Subscribes to every R published on handler's instance, and checks the handler's callback executor against the runtime's owner (detail::checkHandlerExecutor).
 Subscription (Subscription const &)=delete
Subscription & operator= (Subscription const &)=delete
 Subscription (Subscription &&)=delete
Subscription & operator= (Subscription &&)=delete
std::optional< R > const & latest () const
 The latest published value. Tracked.

Detailed Description

template<typename R>
class morph::reactive::Subscription< R >

The latest R the bridge published on a handler's instance, as reactive state.

Uses the handler's one subscription slot for R: two consumers of the same R use two handlers. The subscription is gated by a scope the Subscription owns, so a publish delivered after it is destroyed — one already queued included — is dropped. The handler keeps the dead entry until it is destroyed or subscribes to R again. A delivery off the Runtime's owner is reported (detail::site::kOffOwner) and dropped.

latest() is state, not an event stream: when R compares with ==, a publish equal to the current value does not notify. For something to happen on every publish, use Query::refreshOn.

Template Parameters
RThe published result type.

Definition at line 704 of file control.hpp.

Constructor & Destructor Documentation

◆ Subscription()

template<typename R>
template<typename M, typename S>
morph::reactive::Subscription< R >::Subscription ( Runtime & runtime,
bridge::BridgeHandler< M, S > & handler )
inline

Subscribes to every R published on handler's instance, and checks the handler's callback executor against the runtime's owner (detail::checkHandlerExecutor).

Template Parameters
MThe handler's model type.
SThe handler's sharing policy.
Parameters
runtimeThe runtime. Borrowed: it must outlive the subscription.
handlerThe handler whose instance publishes; its GUI executor must be the runtime's owner. Borrowed: it must outlive the subscription.

Definition at line 714 of file control.hpp.

Member Function Documentation

◆ latest()

template<typename R>
std::optional< R > const & morph::reactive::Subscription< R >::latest ( ) const
inlinenodiscard

The latest published value. Tracked.

Returns
The value, or nullopt before the first publish. Valid until the next publish.

Definition at line 733 of file control.hpp.


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