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

Standard loadable view-model. More...

#include <loadable.hpp>

Public Types

using value_type = T

Public Member Functions

LoadState state () const noexcept
bool is_idle () const noexcept
bool is_loading () const noexcept
bool is_refreshing () const noexcept
bool is_success () const noexcept
bool is_error () const noexcept
bool in_flight () const noexcept
 True iff a fetch is currently in flight (Loading or Refreshing).
bool has_value () const noexcept
 True iff the loadable currently has a value to show (Success, Refreshing, or Error+prior).
bool has_error () const noexcept
 True iff an error is currently surfaced.
const T * value () const noexcept
 Returns a pointer to the value if has_value(), else nullptr.
template<class U>
value_or (U &&fallback) const
 Returns a copy of the value, or constructs T from fallback if absent.
const Errorerror () const noexcept
 Returns a pointer to the error if has_error(), else nullptr.
template<class F>
auto map (F &&f) const -> Loadable< std::remove_cvref_t< std::invoke_result_t< F, const T & > > >

Static Public Member Functions

static Loadable idle () noexcept
static Loadable loading ()
static Loadable refreshing (T prior)
 Build a Refreshing state from an existing Success payload.
static Loadable success (T v)
static Loadable error (Error err)
 Build an Error state.
static Loadable error (Error err, T prior)

Friends

template<class>
class Loadable
bool operator== (const Loadable &a, const Loadable &b)

Detailed Description

template<class T>
class aria::Loadable< T >

Standard loadable view-model.

Stores up to one value (the freshest known good) and up to one error (the last failure). Combined with state() they encode the five-state view-model.

The class is value-typed and equality-comparable so it composes cleanly with Property<Loadable<T>>'s equality-gated set semantics (per lifecycle.md L-21 and error-model.md E-11). It holds no resources of its own.

Member Typedef Documentation

◆ value_type

template<class T>
using aria::Loadable< T >::value_type = T

Member Function Documentation

◆ idle()

template<class T>
Loadable aria::Loadable< T >::idle ( )
inlinestaticnodiscardnoexcept

◆ loading()

template<class T>
Loadable aria::Loadable< T >::loading ( )
inlinestaticnodiscard

◆ refreshing()

template<class T>
Loadable aria::Loadable< T >::refreshing ( T prior)
inlinestaticnodiscard

Build a Refreshing state from an existing Success payload.

prior is the value still on display while the refresh runs.

◆ success()

template<class T>
Loadable aria::Loadable< T >::success ( T v)
inlinestaticnodiscard

◆ error() [1/3]

template<class T>
Loadable aria::Loadable< T >::error ( Error err)
inlinestaticnodiscard

Build an Error state.

If prior is provided the loadable keeps the last good value visible (stale-while-revalidate).

◆ error() [2/3]

template<class T>
Loadable aria::Loadable< T >::error ( Error err,
T prior )
inlinestaticnodiscard

◆ state()

template<class T>
LoadState aria::Loadable< T >::state ( ) const
inlinenodiscardnoexcept

◆ is_idle()

template<class T>
bool aria::Loadable< T >::is_idle ( ) const
inlinenodiscardnoexcept

◆ is_loading()

template<class T>
bool aria::Loadable< T >::is_loading ( ) const
inlinenodiscardnoexcept

◆ is_refreshing()

template<class T>
bool aria::Loadable< T >::is_refreshing ( ) const
inlinenodiscardnoexcept

◆ is_success()

template<class T>
bool aria::Loadable< T >::is_success ( ) const
inlinenodiscardnoexcept

◆ is_error()

template<class T>
bool aria::Loadable< T >::is_error ( ) const
inlinenodiscardnoexcept

◆ in_flight()

template<class T>
bool aria::Loadable< T >::in_flight ( ) const
inlinenodiscardnoexcept

True iff a fetch is currently in flight (Loading or Refreshing).

Mirrors AsyncResource's is_loading Property.

◆ has_value()

template<class T>
bool aria::Loadable< T >::has_value ( ) const
inlinenodiscardnoexcept

True iff the loadable currently has a value to show (Success, Refreshing, or Error+prior).

◆ has_error()

template<class T>
bool aria::Loadable< T >::has_error ( ) const
inlinenodiscardnoexcept

True iff an error is currently surfaced.

Only true in Error state (Loading/Refreshing/Success never carry an error per error-model.md – a fresh fetch clears the previous error).

◆ value()

template<class T>
const T * aria::Loadable< T >::value ( ) const
inlinenodiscardnoexcept

Returns a pointer to the value if has_value(), else nullptr.

◆ value_or()

template<class T>
template<class U>
T aria::Loadable< T >::value_or ( U && fallback) const
inlinenodiscard

Returns a copy of the value, or constructs T from fallback if absent.

◆ error() [3/3]

template<class T>
const Error * aria::Loadable< T >::error ( ) const
inlinenodiscardnoexcept

Returns a pointer to the error if has_error(), else nullptr.

◆ map()

template<class T>
template<class F>
auto aria::Loadable< T >::map ( F && f) const -> Loadable< std::remove_cvref_t< std::invoke_result_t< F, const T & > > >
inlinenodiscard

◆ Loadable

template<class T>
template<class>
friend class Loadable
friend

◆ operator==

template<class T>
bool operator== ( const Loadable< T > & a,
const Loadable< T > & b )
friend

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